满口金牙 2021-10-30 13:52 采纳率: 90.4%
浏览 106
已结题

vue2.0 切换成 vue 3.0 的写法请教!

main.js中有写: app.config.globalProperties.$http = axios

// vue2 的写法
 methods: {
    async project_list () {
      const { data: res } = await this.$http.get('project_list')
      this.data = res
    },

现在我要换成 vue3.0 写法,把上面的代码写到setup(){}中去, vue3.0 没有this,具体怎么写,请改代码,多谢
getCurrentInstance 方法不行,getCurrentInstance 方法好象只用在开发环境中

  • 写回答

2条回答 默认 最新

  • been_ss 2021-10-30 17:02
    关注

    哈喽,我之前有回答过的哦,注意,不要用ctx,用proxy,线上才不会报错。

    const { proxy } = getCurrentInstance()  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月9日
  • 已采纳回答 11月1日
  • 创建了问题 10月30日