Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

vue.js - Vue Props values not passed in simple test

I'm new using VUE and I was testing a simple vue-router but props are not working in this test.

Here the test on jsfiddle

<div id="app">Menu: 
 <router-link to="/">Home</router-link> | 
 <router-link to="/post">Post</router-link> | 
 <router-link to="/foo">Foo link comment</router-link>
 <router-view></router-view>
 </div>


const Home = { template: '<div class="page">Welcome to my Home <router-link :to="{name:'foo'}">this link</router-link></div>' }

const Foo = { 
    props:['comment', 'msg'],
    template: '<div class="page">{{msg}} Here the comment:<hr><div v-html="comment"></div><hr>Go back to <router-link :to="{name:'home'}">home</router-link></div>' }

const router = new VueRouter({
     mode: 'history',
     routes: [
        { path: '/', name:'home',component: Home },
        { path: '/foo', name:'foo', component: Foo }],
   })


 new Vue({
  router,
  el: '#app',
  data: {
     msg: 'Hello World',
     comment : '<div class="comment">This is a <strong>bold</strong> link</div>'
  }
})

And how to pass the router link in prop HTML code?

See the not rendered link

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to add props property in routes attribute

{ path: '/foo', name:'foo', component: Foo , props: true}

Also you need to pass prop value in router-link

<router-link :to="{ name: 'foo', 
      params: { comment: comment,msg: msg }}">Foo link comment</router-link>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...