我有一个可重用的组件,我想在任何我想要的组件中使用它:
reusable.vue
<template>
<div class="example">
<slot></slot>
</div>
</template>
<script>
export default {
methods: {
alertme() {
console.log("hey!");
}
}
};
</script>
在另一个组件中,我想使用该组件(reusable.vue)的方法和数据。等
<template>
<reusable>
<template slot-scope="defaultSlotScope">
<button type="button" class="btn btn-danger" @click="alertme">click me!</button>
</template>
</reusable>
</template>
<script>
import reusable from "../reusable.vue";
export default {
components: {
reusable
}
};
</script>
我收到这个错误:
[Vue warn]: Property or method "alertme" 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. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
这意味着Vue无法识别此方法(Alertme)。
那么,我如何才能让它工作呢?
https://stackoverflow.com/questions/50704847
复制相似问题