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. mysql - 數據庫建表方面的問題?2. javascript - angular里一個關于ng-bind的問題3. mysql - 我用SQL語句 更新 行的時候,發現全部 中文都被清空了,請問怎么解決?4. python - xpath提取網頁路徑沒問題,但是缺失內容?5. javascript - IOS微信audio標簽不能通過touchend播放6. javascript - 求教各位,本地HTML頁面怎么在DIV中嵌套服務器上的頁面內容?不用iframe。7. python-mysql Commands out of sync8. java中這個頁面默認是utf-8編碼的,1輸出亂碼可以理解,可是2就不理解了?9. [前端求職必看]前端開發面試題與答案精選_大綱10. javascript - angularJS指令如何暴露API給外面的controller使用?
