当前位置:网站首页>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=>{
})
边栏推荐
猜你喜欢
深入了解JUC并发(一)什么是JUC
Lucene Basics
Introduce two automatic code generators to help improve work efficiency
In depth understanding of JUC concurrency (II) concurrency theory
队列(线性结构)
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?
Distributed transactions: the final consistency scheme of reliable messages
深入学习JVM底层(二):HotSpot虚拟机对象
数据科学【八】:SVD(一)
随机推荐
日志 - 7 - 记录一次丢失文件(A4纸)的重大失误
LeetCode 47. Full arrangement II
Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
js中正则表达式的使用
BGP报文详细解释
TensorRT中的循环
Cglib agent - Code enhancement test
数据科学【八】:SVD(一)
Redis——大Key问题
LeetCode 40. 组合总和 II
Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
稀疏数组(非线性结构)
Name six schemes to realize delayed messages at one go
IPv6 experiment and summary
kali最新更新指南
ShardingSphere-JDBC篇
The difference between session and cookies
Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music
构建学习tensorflow
TensorRT的数据格式定义详解