返回信息流要完成的功能是点击确定按钮,执行组件中的jug函数 ,触发自定义的judge事件,并且由cmp组件执行del函数,可却会报错:help~~~
[Vue warn]: Property or method "jug" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
<script>
Vue.component('cmp',{
template:'#cmp',
props:['appear'],
data(){
return{
innerdel:''
}
},
methods:{
jug:function(){
this.$emit('judge');
}
}
});
new Vue({
el:'#box',
data:{
arr:[{name:'name1',sex:'woman',age:'11'},
{name:'name2',sex:'man',age:'12'},
{name:'name3',sex:'woman',age:'13'}
],
name:'',
age:'',
sex:'',
nowIndex:0,
modal:'',
layer:'#laye',
appear:false
},
methods:{
add:function(){
this.arr.push({
name:this.name,
age:this.age,
sex:this.sex
});
},
del:function(_id){
if(_id==-2){
this.arr=[];
}else{
this.arr.splice(_id,1);
}
},
test:function(mod){
alert('modal'+mod);
},
appr:function(ind){
this.appear=true;
}
}
});
</script>
<div>
<cmp v-on:judge="del(nowIndex)"></cmp>
</div>
<template id="cmp">
<div v-show="appear" :class="['shade']">
<div :class="['wrapper']">
<div :class="['wrapper-head']">
<button type="button" :class="['icon-close']" @click="appear=false;">
<span>×</span><!--×号-->
</button>
<p>确定要删除吗?</p>
</div>
<div :class="['wrapper-body']">
<button :class="['but','no']" type="button" @click="appear=false;">取消</button>
<button :class="['but','yes']" type="button" @click="jug;appear=false;">确定</button>
</div>
</div>
</div>
</template>
这是一条镜像帖。来源:北邮人论坛 / java-script / #3678同步于 2018/3/17
该镜像源已超过 30 天没有更新,可能在源站已被删除。
JavaScript机器人发帖
【问题】vue 报错:组件中methods的方法未定义
sugelan
2018/3/17镜像同步1 回复
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复