请求this vue绑定的不一致

来源:6-7 封装请求总结&说明

weixin_慕雪8557995

2022-08-10 10:48:06

关于全局封装 接口请求那块.  

我已经打印了 install 插件是都可以运行的. 

且在main.js 里也注册Vue.use过了.

但是在page页面 打印this.$u.api 是找不到的.

在页面page  打印vue.prototype.$u.api 是找得到的


很困惑.this居然 不是vue的实例

如何解决?


https://img.mukewang.com/climg/62f31baf09cd5e6f09020548.jpg

https://img.mukewang.com/climg/62f31bbc098d339515600692.jpg

上面两个都正常 也走了 也打印了  如下

https://img.mukewang.com/climg/62f31bf409fa398621400806.jpg


但是在页面使用就找不到 .如下图

https://img.mukewang.com/climg/62f31c0809a03b8614540378.jpg

https://img.mukewang.com/climg/62f31c3109bd323e22400372.jpg




请老师帮我解答一下啊

相关代码:

import Vue from 'vue'
import App from './App'

// uview
import uView from 'uview-ui'
// *****************全局接口请求**************
import httpUtils from '@/common/plugins/http-uview'
import interceptors from '@/common/interceptors'
import apis from '@/api'

Vue.use(uView)
Vue.use(httpUtils)
Vue.use(interceptors)
Vue.use(apis)

// *****************全局接口请求**************

//数据管理中心
import store from '@/store'
Vue.prototype.$store = store

// 工具
// import '@/plugins/utils.js'

//权限配置中心
import base from '@/config/baseUrl'
Vue.prototype.$base = base

//挂载全局http请求
// import $http from '@/config/requestConfig'
// Vue.prototype.$http = $http

// #ifdef MP-WEIXIN
//挂载全局微信分享
import { wxShare } from '@/config/utils'
Vue.prototype.wxShare = wxShare
// #endif

//判断是否登录
import { judgeLogin } from '@/config/login'
Vue.prototype.judgeLogin = judgeLogin
Vue.config.productionTip = false

// #ifdef H5
//微信SDK
// import '@/plugins/wxJsSDK.js'
// #endif

//全局组件
import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
Vue.component('mescroll-body', MescrollBody)
App.mpType = 'app'

// uview
// import '@/plugins/uview.js'

const app = new Vue({
store,
...App
})
app.$mount()


写回答

1回答

Brian

2022-09-04

是版本问题,uview用1.x的版本!

0

大前端2022版

1个业务场景打通全端、全栈、全流程,实现全局思维与综合技术能力全面突破;对标阿里P6,8个月成为前端高级人才

2840 学习 · 691 问题

查看课程