当前位置:网站首页>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=>{
})边栏推荐
- AWD学习
- CUDA中内置的Vector类型和变量
- CUDA与Direct3D 一致性
- Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
- Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table
- 底层机制Mvcc
- 一口气说出 6 种实现延时消息的方案
- Redis——Cluster数据分布算法&哈希槽
- In depth understanding of JUC concurrency (II) concurrency theory
- Generic classes and parameterized classes of SystemVerilog
猜你喜欢
随机推荐
Network related knowledge (Hardware Engineer)
Zhuanzhuanben - LAN construction - Notes
CUDA中内置的Vector类型和变量
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
PgSQL学习笔记
Decryption skills of encrypted compressed files
Support new and old imperial CMS collection and warehousing tutorials
AWD学习
RestTemplate请求时设置请求头,请求参数,请求体。
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
CUDA用户对象
Use of Arduino wire Library
LeetCode 90. Subset II
Learn about various joins in SQL and their differences
CUDA中的线程层次
【每日一题】—华为机试01
Redis - big key problem
The intern left a big hole when he ran away and made two online problems, which made me miserable
Lucene Basics
Linked list (linear structure)








