Nuxt val.replace is not a function when get asyncData from APIs

1k views Asked by At

my intention is to get some data from api,

then put in the head(){} to set description and title,

but it keep telling me val.replace is not a function,

here is my code

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,
        },

Uncaught TypeError: val.replace is not a function

thanks for answering

1

There are 1 answers

0
Ilijanovic On BEST ANSWER

Thats not the way to use asyncData.

Your API call should be called inside the asyncData and then return your data