【问题标题】:Nuxt val.replace is not a function when get asyncData from APIs从 API 获取 asyncData 时 Nuxt val.replace 不是函数
【发布时间】:2021-03-07 02:57:48
【问题描述】:

我的目的是从 api 获取一些数据,

然后放入head(){}中设置描述和标题,

但它一直告诉我 val.replace 不是函数,

这是我的代码

async mounted() {
...await call api...
    if (resDataGetNewsInfo.return_code === 0) {
      vm.newsInfoObj = resDataGetNewsInfo.return_msg;
    } else {
      ...
    }

...

  asyncData() {
    return {
      newsInfoObj: '',
    };
  },

...

  head() {
    return {
      description: this.newsInfoObj.news_short_desc,
      meta: [
        {
          hid: 'og:title',
          property: 'og:title',
          content: this.newsInfoObj.news_title,
        },

未捕获的类型错误:val.replace 不是函数

感谢回答

【问题讨论】:

    标签: vue.js nuxt.js meta head asyncdata


    【解决方案1】:

    这不是使用asyncData的方式。

    您的 API 调用应在 asyncData 内调用,然后返回您的数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2019-03-25
      • 2022-11-11
      • 2019-12-11
      • 2019-10-07
      • 1970-01-01
      相关资源
      最近更新 更多