在普通js文件中引用Vue实例
做app更新检测时,我想在lib.js使用uView的Http请求插件
首先我在main.js中use了uview这个UI框架。
//main.js
import uView from 'uview-ui';
Vue.use(uView);
于是我在lib.js中引入vue,实例化后,就可以使用挂载在vue上的属性和方法了
//lib.js
let vm = new Vue();
const update = function() {
console.log('check update');
vm.$u.get('/update',{
appid:plus.runtime.appid,
version:plus.runtime.version
}).then(res=>{
if(res){
vm.$u.route({
url:'/pages/update/update',
animationType:'fade-in',
params:res
})
}
})
}
import Vue from 'vue'; //引入vue
export default {
update
}