当前位置:网站首页>FE - Weex 使用简单封装数据加载插件为全局加载方法
FE - Weex 使用简单封装数据加载插件为全局加载方法
2022-07-02 06:22:00 【原小明】
前言
将 weex 的网络加载方式 fetch 简单封装下,在全局组件中进行使用;基本思路:
- 封装 fetch 插件
- 在 vue 中进行注册
- 组件中进行使用
插件封装
如代码所示,注意使用 vue.mixin 方法即可
/** * Created by yuan on 2017/11/1. * weex 网络请求操作 */
const BASE_URL = "http://192.168.3.16:8080"
const stream = weex.requireModule('stream')
function get(repo, callback) {
return stream.fetch({
method: 'GET',
type: 'json',
url: BASE_URL + repo
}, callback)
}
export default {
install: function (Vue, options) {
// 添加的内容写在这个函数里面
Vue.mixin({
methods: {
get: function (repo, callback) {
get(repo, callback)
}
}
})
}
}
注册插件
在 main.js (entry.js )中进行注册插件
import http from './service/http'
// setting http
Vue.use(http)
使用
直接在 组件的 methods 中进行调用即可;
this.get('/login',res=>{
})
边栏推荐
- Redis - cluster data distribution algorithm & hash slot
- Don't use the new WP collection. Don't use WordPress collection without update
- Is there a really free applet?
- 日期时间API详解
- IDEA公布全新默认UI,太清爽了(内含申请链接)
- Singleton mode compilation
- 深入学习JVM底层(三):垃圾回收器与内存分配策略
- Data science [viii]: SVD (I)
- 实习生跑路留了一个大坑,搞出2个线上问题,我被坑惨了
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
猜你喜欢
Introduce two automatic code generators to help improve work efficiency
Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table
Lucene Basics
ShardingSphere-JDBC篇
LeetCode 90. Subset II
Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music
栈(线性结构)
Amazon AWS data Lake Work Pit 1
最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
Code skills - Controller Parameter annotation @requestparam
随机推荐
日期时间API详解
AWD学习
Zhuanzhuanben - LAN construction - Notes
自学table au
Use of Arduino wire Library
CUDA中的Warp Shuffle
注解和反射详解以及运用
奇葩pip install
Sentinel规则持久化到Nacos
最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
Distributed transactions: the final consistency scheme of reliable messages
The intern left a big hole when he ran away and made two online problems, which made me miserable
LeetCode 39. Combined sum
TensorRT中的循环
深入学习JVM底层(五):类加载机制
Redis——Cluster数据分布算法&哈希槽
In depth understanding of JUC concurrency (I) what is JUC
CUDA中的异步数据拷贝
Introduce two automatic code generators to help improve work efficiency