javascript - vue中自定義事件如何傳遞參數?
問題描述
如代碼所示,在子組件中定義和觸發了select方法并將type參數傳入,在父組件中引入子組件,并監聽select事件
結果報錯:“Property or method 'type' is not defined on the instance but referenced during render.” 是我傳遞參數的方法不對嗎?
//子組件<button type='button' name='button' v-bind: v-on:click='select(2,$event)'> {{desc.all}} <span class='count'>{{ratings.length}}</span></button><script type='text/ecmascript-6'> methods:{ select:function (type,event) {if (!event._constructed){ return;}this.$emit(’select’,type) }</script>
//父組件<rating-select v-bind='{ratings:food.ratings,selectType:selectType,onlyContent:onlyContent}' v-on:select='updSelect(type)' v-on:toggleContent='toggleContent' class='rating-select'></rating-select><script> updSelect:function (type) {this.selectType = type }</script>
問題解答
回答1:v-on:select='updSelect'
相關文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. 配置Apache時,添加對PHP的支持時語法錯誤4. 實現bing搜索工具urlAPI提交5. javascript - vue-router 地址改變數據未改變6. javascript - html5多個label中其中一個觸發change,如何判斷是哪一個出發了change7. javascript - 移動端上不能實現拖拽布局嗎?8. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~9. phpstudy8.1支持win11系統嗎?10. javascript - nodejs關于進程間發送句柄的一點疑問

網公網安備