【问题标题】:plugin function undefined in nuxt.jsnuxt.js 中未定义的插件功能
【发布时间】:2021-06-20 00:23:59
【问题描述】:

纪录片 nuxt.js 表明它有效。 Link 但是当我在我的组件生命周期挂钩上调用我的插件函数“已安装”时,它会显示“TypeError:无法读取未定义的属性'$ProgramApi'”。 但是在常规方法中,插件在同一个组件中可以正常工作。所以设置一定是对的

我对 nuxt 还是很陌生。

<script>
export default {
  data()  {
    return {
      programs: []
    }
  },
  mounted: () => {
    console.log(this.$ProgramApi.agenda());
  },
  methods: {
    test() {
      this.$ProgramApi.conferenceRooms().then(res => {
        console.log(res);
      });
    }
  }
}
</script>

【问题讨论】:

    标签: javascript vue.js nuxt.js


    【解决方案1】:

    mounted 函数更改为常规函数。不要使用 ES-6 语法。

    代替:

    mounted: () => {
      console.log(this.$ProgramApi.agenda()); // this will refer to mounted instance
    },
    

    使用:

    mounted() {
      console.log(this.$ProgramApi.agenda()); // this will refer to vue instance
    },
    

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 1970-01-01
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2019-07-25
      • 2021-01-15
      • 2019-02-20
      相关资源
      最近更新 更多