2016-12-15 59 views
2

我有一個分量這樣看,界定「名」和「佔位」性質:數據通過道具不會被渲染通過使用時

Vue.component("text-control", { 
    props: { 
     name: String, 
     placeholder: {type: String, default: ""}, 
    }, 
    template: '<div class="form-group"><label>{{name}}</label> <input class="form-control" type="text" placeholder="{{placeholder}}"></div>' 
}); 

叫一樣,我的網頁上:

<text-control name="Name" placeholder="Enter Name here"></text-control> 

名稱屬性被正確解析。但我無法獲得佔位符屬性值的工作。它顯示我{{placeholder}}而不是Enter Name here。我如何將屬性綁定到模板中的屬性值?

回答

2

在Vue公司2.0,您不能使用屬性{{}}等,您應該使用V-綁定:

<input class="form-control" type="text" v-bind:placeholder="placeholder">