【发布时间】:2019-01-26 00:58:12
【问题描述】:
尝试使用vue-meta
我不明白如何根据 XHR 响应设置标题。到目前为止,我有:
<script>
export default {
name: 'Model',
data() {
return {
model: [],
}
},
metaInfo: {
title: 'Default Title',
titleTemplate: '%s - site slogan'
},
methods: {
getModels() {
window.axios.get(`/api/${this.$route.params.manufacturer}/${this.$route.params.model}`).then((response) => {
this.model = response.data;
this.metaInfo.title = response.data.model_name; // THIS NOT WORKING
});
}
},
watch: {
$route(to, from) {
if ( to.name === 'model' ) {
this.getModels();
}
},
},
created() {
this.getModels();
}
}
</script>
当我尝试设置时
this.metaInfo.title = response.data.model_name;
出现错误:未捕获(承诺中)TypeError:无法设置未定义的属性“标题”
所以 this.metaInfo 是未定义的...
我的头衔需要基于 XHR 请求的响应。
【问题讨论】:
标签: vue.js vuejs2 vue-component vue-router