【发布时间】:2020-12-16 10:07:30
【问题描述】:
我正在检查某人的代码。它们在计算中具有以下内容:
computed: {
requireParams() {
return {
coach: this.coach,
sid: this.sid
};
},
coach() {
return this.$route.params.coach || {};
},
sid() {
return this.$route.params.sid || null;
},
avatar() {
if (
this.coach.profile_pic &&
this.coach.profile_pic.indexOf("http") !== -1
) {
return this.coach.profile_pic;
} else {
return "/images/_avatar.jpg";
}
}
}
现在在 html 模板代码中,coach 被多次引用,就像这样
<p class="name">{{coach.last_name}}{{coach.first_name}}</p>
谁能解释一下教练是如何在路线中发送对象的?我认为只有字符串可以在路由中发送,例如 /path/:id 会转换为 /path/2 所以 $route.params 会给出 {id: 2}。
但是这里的教练正在路由中被访问,它显然是一个对象?我不明白这怎么可能
【问题讨论】:
-
查看 router.js
-
计算属性可以注入模板,你可以在这里找到文档docs
-
请看看我的编辑
-
代码有效吗?还是
<p class="name">{{coach.last_name}}{{coach.first_name}}</p>呈现为undefinedundefined
标签: javascript vue.js vuejs2