你好,我在項目中使用 vuejs2 和 laravel 我問是否可以像這樣將數據從插槽傳遞到組件 Vue.component('search_and_select',{ template: '<div>'+ <slot name='Slot_name'></slot> '</div>', data:function(){ return { this_is_test_data:null, custom_method_here:null, custom_model :null } }, methods:{ custom_method_here:function() { // code here } }, props:{}});這是html代碼<div is='search_and_select' > <div slot='Slot_name'> <!-- is is possible to write code here like this <input type='text' @keyup='custom_method()' v-model='custom_model' /> --> </div></div>我也可以做這個代碼嗎?如果沒有的話,任何人都可以幫助我如何做這樣的事情..
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
這就是slot-scope為了
在你的代碼中,它看起來像這樣......
Vue.component('search_and_select',{
template:
'<div>'+
<slot name='Slot_name'></slot>
'</div>',
data:function(){
return {
this_is_test_data:null,
custom_method:null,
custom_model:null
}
},
methods:{
custom_method:function()
{
// code here
}
},
props:{}
});
這是html代碼
<div is='search_and_select' >
<div slot='Slot_name' slot-scope="{ custom_method, custom_model}">
<input type='text' @keyup='custom_method()' v-model='custom_model' />
</div>
</div>
- 1 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消