Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js NuxtJS-在已安装的设备上设置标题/说明?_Vue.js_Nuxt.js - Fatal编程技术网

Vue.js NuxtJS-在已安装的设备上设置标题/说明?

Vue.js NuxtJS-在已安装的设备上设置标题/说明?,vue.js,nuxt.js,Vue.js,Nuxt.js,基本上,我有一个json“线程”的常量文件,我想使用它的属性来设置head-title/description 我收到这个错误: 无法读取未定义的属性“thread”您应该在数据方法中定义thread mounted() { // threads is a constant file this.thread = threads.find(t => t.id === this.$route.params.id) }, data() { return { thread: n

基本上,我有一个json“线程”的常量文件,我想使用它的属性来设置head-title/description

我收到这个错误:

无法读取未定义的属性“thread”

您应该在数据方法中定义
thread

mounted() {
  // threads is a constant file
  this.thread = threads.find(t => t.id === this.$route.params.id)
},
data() {
  return {
    thread: null
  }
},
head: {
  title: this.thread.title,
  meta: [
    {
      hid: 'description',
      name: 'description',
      content: this.thread.body
    }
  ]
},
此外,头应该定义为方法,而不是属性

data () {
  return {
    thread: {
      body: '',
    }
  }
}

您应该在数据方法中定义
线程

mounted() {
  // threads is a constant file
  this.thread = threads.find(t => t.id === this.$route.params.id)
},
data() {
  return {
    thread: null
  }
},
head: {
  title: this.thread.title,
  meta: [
    {
      hid: 'description',
      name: 'description',
      content: this.thread.body
    }
  ]
},
此外,头应该定义为方法,而不是属性

data () {
  return {
    thread: {
      body: '',
    }
  }
}

显然,您必须从这里删除null

head () {
  return {
    meta: [
      {
        hid: 'description',
        name: 'description',
        content: this.thread.body
      }
    ]
  }
}
并将其插入异步方法中

thread: null => thread: ""

最好的

显然,您必须从这里删除null

head () {
  return {
    meta: [
      {
        hid: 'description',
        name: 'description',
        content: this.thread.body
      }
    ]
  }
}
并将其插入异步方法中

thread: null => thread: ""
最好的

从中,类型为对象函数

因此,如果您重新格式化代码,您可以像这样编写
head

   async getId() {
    this.thread = await threads.find(t => t.id === this.$route.params.id)
   }
从中,类型为对象函数

因此,如果您重新格式化代码,您可以像这样编写
head

   async getId() {
    this.thread = await threads.find(t => t.id === this.$route.params.id)
   }

这个怎么样:这个怎么样:head应该定义为具有返回值的函数,就像data函数一样head(){return{meta:[{hid:'description'}]}}}``应该将head定义为具有返回值的函数,类似于数据函数。````````head(){return{meta:[{hid:'description'}]}}``我现在无法测试这个,所以如果有帮助,请告诉我:)哦。。它起作用了,但只是为了描述。标题没有更改(nuxt仍然显示在nuxt.config上定义的默认标题模板。我在nuxt config上删除了标题模板,并且成功了。谢谢!我现在无法对此进行测试,因此如果有帮助,请告诉我:)哦。。它起作用了,但只是为了描述。标题没有更改(nuxt仍然显示nuxt.config上定义的默认标题)。我删除了nuxt config上的标题模板,并且成功了。谢谢!