【发布时间】:2022-01-13 19:12:34
【问题描述】:
我有一个带有 Vue 前端的 Strapi 后端平台。我正在尝试在首页上显示内容,但遇到了问题。
它调用数据没有问题,并在我放入时显示在console.log中。但是,在Vue数据中,数组保持为空,因此根本不会显示数据。我希望它显示的页面上的脚本中是否缺少某些内容?下面是具体的脚本代码。
再一次,try/catch 中的返回实际上显示了数据。这是 Vue 数据中不想填充的返回
<script>
import Vue from "vue";
export default {
name: "whatsNew",
async beforeRouteEnter(to, from, next) {
try {
var WhatsNew = await Vue.$whatsNewService.findOne(to.params.id);
return next((vm) => {
vm.WhatsNew = WhatsNew;
console.log(WhatsNew.title);
});
} catch (err) {
console.log(err);
next(false);
}
},
data() {
return {
whatsNew: [],
};
},
};
</script>
【问题讨论】: