在main.js
我有这样的事情:
import { myUtilFunc} from './helpers';
Object.defineProperty(Vue.prototype, '$myUtilFunc', { value: myUtilFunc });
Run Code Online (Sandbox Code Playgroud)
通过这种方式,我可以访问myUtilFunc
整个应用程序this.$myUtilFunc
但是,setup()
如果我无法访问 Vue 3中的方法,我该如何实现this
?
文档说要this.$axios.$get()
在 of 内部使用methods/mounted/etc
,但是TypeError: _this is undefined
在 of 内部调用时会抛出异常setup()
。$axios
与组合 API 兼容吗?
为了澄清一下,我专门谈论 axios nuxt 插件,而不仅仅是一般使用 axios。https://axios.nuxtjs.org/
例如,类似这样的事情会引发上面的错误
export default {
setup: () => {
const data = this.$axios.$get("/my-url");
}
}
Run Code Online (Sandbox Code Playgroud)