2016-12-10 74 views
5

我如何將道具傳遞給javascript Vue componentvuejs:將道具傳遞給javascript中的組件?

這是我通常這樣做的。

<child prop="value"></value> 

,但我想這樣做,這樣

var Child = Vue.extend({ 
    ... 
}); 
Chid.passProps({foo: 'bar'}) // some thing like this? 

這可能在vue.js?

這是全碼:

var Child = Vue.extend({ 
    props: ['foo'], 
    methods: { 
     printIt: function() { 
      console.log(this.foo) 
     } 
    }, 
    template: '#example' 
}); 
var vm = new Vue({ 
    el: '#root', 
    data: { 
     foo: 'bar' 
    }, 
    render: function(createElement) { 
     return createElement(Child); // pass down foo 
    } 
}); 

link to jsbin

回答

相關問題