子组件调用父组件方法,把子组件this当参数传进去,报错!
父组件:
<template>
<view class="parent">
<text>我是父组件</text>
<slot />
</view>
</template>
<script>
export default {
data () {
return {
items: []
}
},
mounted() {
console.log(this.items)
},
methods: {
register(item) {
const index = this.items.push(item) - 1
}
}
}
</script>
子组件:
<template>
<view class="child">
<text>我是子组件</text>
</view>
</template>
<script>
export default {
created() {
if (this.$parent) this.$parent.register(this)
}
}
</script>
子组件调用父组件register方法,参数除了this都正常,传了this就报错:
普通vue是可以的!