vue.js - fetch() 方法在 Nuxtjs 的组件中使用时抛出错误
问题描述
我fetch()
在导航组件中使用方法,但是当我运行我的应用程序时,我看到了[Vue warn]: Property or method "menus" 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.
。
我在导航中的脚本代码。
export default {
name: 'AppHeader',
methods: {
async fetch ({ $content }) {
const menus = await $content('menu').fetch()
return {
menus
}
}
}
}
我试图在数据中添加菜单数组,但没有运气。
export default {
name: 'AppHeader',
data () {
return {
menus: []
}
},
methods: {
async fetch ({ $content }) {
const menus = await $content('menu').fetch()
return {
menus
}
}
}
}
解决方案
推荐阅读
- c# - 如何使用 AutoMapper 中的自定义逻辑从其他属性映射属性?
- android - 如何在材质按钮的一侧添加边框颜色?
- python - Airflow KubernetesExecutor 调度程序 kube watch 进程死亡
- angular - 如何在 Ionic 4 中使用 Firebase 处理刷新令牌?
- e2e-testing - 赛普拉斯测试项目清单。没有收到任何物品时出错?
- javascript - 如何在 sweetalert 中采取两个选项并根据该选项采取行动?
- c++ - 如何使用 C++ 进行矩阵行和列命名?
- python - 两个列表给出相同值的列表的逻辑错误
- python-3.x - 如何绘制两个变量的分布?
- c++ - 哪个是处理虚拟析构函数的更好方法?