内容简介:we-script 让微信小程序支持加载远程 JavaScript 脚本,支持 ES5 语法 Github地址:https://github.com/bplok20010/we-script 最近更新内容 src 支持数组 新增 once ,相同上下文及相同地址的脚本只执行一次 新增...
we-script
让微信小程序支持加载远程 JavaScript 脚本,支持 ES5 语法
Github地址:https://github.com/bplok20010/we-script
最近更新内容
- src 支持数组
- 新增 once ,相同上下文及相同地址的脚本只执行一次
- 新增 onInit 事件
使用
小程序如何使用 npm 包,官方文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html
npm install --save we-script
step1 安装完成后,点击开发者 工具 中的菜单栏:工具 --> 构建 npm
step2 安装完成后,点击开发者工具中的菜单栏:工具 --> 项目详情 --> 本地设置 --> [勾选] 使用 npm 模块
在需要用的页面或组件的json
文件添加声明,示例:
index.json
{
"usingComponents": {
"we-script": "we-script"
}
}
index.wxml
<we-script src="url"> <view>hello we-script<view> </we-script>
注:多个we-script
会并行加载及无序执行,无法保证执行顺序。如:
// 并行加载及无序执行 <we-script src="url1" /> <we-script src="url2" /> <we-script src="url3" />
如需要确保执行顺序,应该使用数组,例如:
数组方式
<we-script src="{{[url1,url2,url3]}}"> <view>hello we-script<view> </we-script>
we-script
也支持嵌套,如:
<we-script src="url1"> <we-script src="url2"> <view>hello we-script<view> </we-script> </we-script>
注意: 在嵌套的情况下we-script
加载和执行也是并行且无序的,因为小程序生命周期触发机制导致,如果想在嵌套模式下保证顺序,需要自己手动控制,示例:
<we-script bind:onLoad="loadScript" src="url1"> <we-script wx:if="url1_load_success" src="url2"> <view>hello we-script<view> </we-script> </we-script>
重要: 远程加载执行的代码所生成的函数,变量等数据存储在we-script
默认的上下文
中,可通过onLoad
事件获取默认上下文
,或通过onInit
事件获取上下文或自定义上下文
。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Firefox 也将支持不可见图片延迟加载功能
- NGINX Plus 18 版本发布,支持动态证书加载
- DataGear 1.8.1 发布,看板支持异步加载图表和参数传入
- React Suite 3.1.0 版本发布,支持按需加载
- nginx 稳定版 1.16.0 发布,支持动态加载 SSL 证书
- nginx 稳定版 1.16.0 发布,支持动态加载 SSL 证书
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Where Wizards Stay Up Late
Katie Hafner / Simon & Schuster / 1998-1-21 / USD 16.00
Twenty five years ago, it didn't exist. Today, twenty million people worldwide are surfing the Net. "Where Wizards Stay Up Late" is the exciting story of the pioneers responsible for creating the most......一起来看看 《Where Wizards Stay Up Late》 这本书的介绍吧!