Javascript 在插槽和组件VUEJ之间传递数据
hi-im在项目中使用vuejs2和laravel 我想问的是,是否可以将数据从插槽传递到组件 像这样Javascript 在插槽和组件VUEJ之间传递数据,javascript,html,laravel,vuejs2,Javascript,Html,Laravel,Vuejs2,hi-im在项目中使用vuejs2和laravel 我想问的是,是否可以将数据从插槽传递到组件 像这样 Vue.component('search_and_select',{ template: '<div>'+ <slot name='Slot_name'></slot> '</div>', data:function(){ return { this_is
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:{}
});
Vue.component('搜索并选择'{
模板:
''+
'',
数据:函数(){
返回{
这是测试数据:null,
此处的自定义方法:null,
自定义模型:null
}
},
方法:{
自定义方法:函数()
{
//代码在这里
}
},
道具:{}
});
这是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>
我可以做这个代码,如果没有任何人可以帮助我如何做这样的事情 这就是slot scope
的作用
在您的代码中,它看起来像这样
Vue.component('搜索并选择'{
模板:
''+
'',
数据:函数(){
返回{
这是测试数据:null,
自定义方法:null,
自定义模型:null
}
},
方法:{
自定义方法:函数()
{
//代码在这里
}
},
道具:{}
});
这是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>
不清楚您在哪里定义自定义方法
和自定义模型
它们在组件方法中