javascript - vue中自定義事件如何傳遞參數(shù)?
問題描述
如代碼所示,在子組件中定義和觸發(fā)了select方法并將type參數(shù)傳入,在父組件中引入子組件,并監(jiān)聽select事件
結(jié)果報(bào)錯(cuò):“Property or method 'type' is not defined on the instance but referenced during render.” 是我傳遞參數(shù)的方法不對(duì)嗎?
//子組件<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'
相關(guān)文章:
1. nignx - docker內(nèi)nginx 80端口被占用2. python3.x - python連oanda的模擬交易api獲取json問題第五問3. docker - 如何修改運(yùn)行中容器的配置4. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類5. docker-machine添加一個(gè)已有的docker主機(jī)問題6. angular.js - angular內(nèi)容過長展開收起效果7. 為什么我ping不通我的docker容器呢???8. node.js - 我是一個(gè)做前端的,求教如何學(xué)習(xí)vue,node等js引擎?9. javascript - js代碼獲取驗(yàn)證碼倒計(jì)時(shí)問題10. 關(guān)于docker下的nginx壓力測試
