亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在slot和vuejs組件之間傳遞數據

在slot和vuejs組件之間傳遞數據

溫溫醬 2023-08-21 19:39:07
你好,我在項目中使用 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>


查看完整回答
反對 回復 2023-08-21
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號