当前位置:网站首页>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=>{
})边栏推荐
- Don't use the new WP collection. Don't use WordPress collection without update
- 代码技巧——Controller参数注解@RequestParam
- 深入学习JVM底层(四):类文件结构
- 浅谈三点建议为所有已经毕业和终将毕业的同学
- 深入学习JVM底层(五):类加载机制
- Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
- In depth understanding of JUC concurrency (I) what is JUC
- Lucene Basics
- 构建学习tensorflow
- js中正则表达式的使用
猜你喜欢

Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish

PgSQL学习笔记

亚马逊aws数据湖工作之坑1

Amazon AWS data Lake Work Pit 1

Redis - big key problem

Find the highest value of the current element Z-index of the page

Summary of WLAN related knowledge points

BGP报文详细解释

Introduce two automatic code generators to help improve work efficiency

日期时间API详解
随机推荐
锐捷EBGP 配置案例
Is there a really free applet?
DeprecationWarning: .ix is deprecated. Please use.loc for label based indexing or.iloc for positi
LeetCode 47. 全排列 II
Lucene Basics
CUDA中内置的Vector类型和变量
深入学习JVM底层(二):HotSpot虚拟机对象
CUDA中的异步数据拷贝
Introduce two automatic code generators to help improve work efficiency
Amazon AWS data Lake Work Pit 1
Bgp Routing preference Rules and notice Principles
Contest3147 - game 38 of 2021 Freshmen's personal training match_ A: chicken
Network related knowledge (Hardware Engineer)
BGP 路由優選規則和通告原則
CUDA中的函数执行空间说明符
Golang--map扩容机制(含源码)
链表(线性结构)
IDEA公布全新默认UI,太清爽了(内含申请链接)
Mech 3002 explanation
Redis - big key problem