前端技术uni-app学习每个 .vue 文件最多包含一个 < template> 块。 每个 .vue 文件最多包含一个 < script> 块。 一个 .vue 文件可以包含多个 < style> 标签。 导入 < script src="./script.js"> uni-app框架目前仅支持长度单位 px 和 %。 PS:uni-app 的基准宽度为 750px。 样式导入作者王明昌发布时间2019-04-30最后更新2019-04-30文章目录生命周期数据绑定class style 绑定事件处理、事件绑定、事件传参组件uni.request(OBJECT) 发起网络请求图片的相关接口上传数据缓存设备相关交互反馈设置导航条导航下拉树新上拉加载更多小程序登陆h5+app登陆自定义组件 每个 .vue 文件最多包含一个 < template> 块。 每个 .vue 文件最多包含一个 < script> 块。 一个 .vue 文件可以包含多个 < style> 标签。 导入 < script src="./script.js"> uni-app框架目前仅支持长度单位 px 和 %。 PS:uni-app 的基准宽度为 750px。 样式导入 复制 pages.json 配置(tabbar/窗口) http://www.hcoder.net/tutorials/info_1339.html 生命周期 onLoad 监听页面加载,其参数为上个页面传递的数据,参数类型为object(用于页面传参),参考示例 onShow 监听页面显示 onReady 监听页面初次渲染完成 onHide 监听页面隐藏 onUnload 监听页面卸载 onPullDownRefresh 监听用户下拉动作 onReachBottom 页面上拉触底事件的处理函数 onShareAppMessage 用户点击右上角分享 微信小程序 onPageScroll 监听页面滚动 onTabItemTap 当前是 tab 页时,点击 tab 时触发。 数据绑定复制data: { title: 'Hello', name : 'hcoder' }, ..... {{title}} 列表渲染复制 {{index}} - {{item.name}} data: { students : [ {name : "张三", age : 18}, {name : "李四", age : 20} ] }, 条件渲染复制 这里是条件展示的内容.... show:false hidden复制 这里是条件展示的内容.... class style 绑定复制111 222333 444 555 666 777 事件处理、事件绑定、事件传参 web uniapp 对应表 click: 'tap', touchstart: 'touchstart', touchmove: 'touchmove', touchcancel: 'touchcancel', touchend: 'touchend', tap: 'tap', longtap: 'longtap', input: 'input', change: 'change', submit: 'submit', blur: 'blur', focus: 'focus', reset: 'reset', confirm: 'confirm', columnchange: 'columnchange', linechange: 'linechange', error: 'error', scrolltoupper: 'scrolltoupper', scrolltolower: 'scrolltolower', scroll: 'scroll' 在 input 和 textarea 中 change 事件会被转为 blur 事件。 事件绑定 @click 复制 methods:{ clickTest: function(e){ console.log(e); console.log('click'); }, longtap: function(e){ console.log(e); console.log('longtap'); } } 事件传参 复制 {{index}} - {{item.name}} menuClick : function(e){ console.log(e); console.log(e.target.id); } 组件 基本组件 https://uniapp.dcloud.io/component/README 表单组件 http://uniapp.dcloud.io/component/button navigator http://www.hcoder.net/tutorials/info_1347.html 复制 跳转到新页面 媒体组件 地图组件 复制 markers: [{ width : 40, height: 40, latitude: 39.909, longitude: 116.39742, iconPath: '../../../static/p.png' }] uni.request(OBJECT) 发起网络请求 get 复制 uni.request({ url: 'https://demo.hcoder.net', success: function (res) { console.log(res.data); } post 复制uni.request({ url: 'https://demo.hcoder.net/index.php', data: {name : 'hcoder...', 'age' : 18}, method:"POST", header : {'content-type':'application/x-www-form-urlencoded'}, success: function (res) { console.log(res.data); } }); 图片的相关接口 http://www.hcoder.net/tutorials/info_1351.html 复制uni.chooseImage(OBJECT) 从本地相册选择图片或使用相机拍照。 uni.chooseImage({ count: 6, //默认9 sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 sourceType: ['album'], //从相册选择 success: function (res) { console.log(JSON.stringify(res.tempFilePaths)); } }); 预览图片 uni.chooseImage({ count: 6, sizeType: ['original', 'compressed'], sourceType: ['album'], success: function (res) { // 预览图片 uni.previewImage({ urls: res.tempFilePaths }); } }); uni.getImageInfo(OBJECT) 获取图片信息 uni.chooseImage({ count: 1, sourceType: ['album'], success: function (res) { uni.getImageInfo({ src: res.tempFilePaths[0], success: function (image) { console.log(image.width); console.log(image.height); } }); } }); uni.saveImageToPhotosAlbum(OBJECT)保存图片到系统相册 uni.saveImageToPhotosAlbum({ filePath: res.tempFilePaths[0], success: function () { console.log('save success'); } }); 上传 uni.uploadFile(OBJECT) 客户端发起一个 POST 请求,其中 content-type 为 multipart/form-data。 复制 选择照片 getExeName($_FILES['file']['name']); if($exename != 'png' && $exename != 'jpg' && $exename != 'gif'){ exit('不允许的扩展名'); } $imageSavePath = uniqid().'.'.$exename; if(move_uploaded_file($_FILES['file']['tmp_name'], $imageSavePath)){ echo $imageSavePath; } } } public function getExeName($fileName){ $pathinfo = pathinfo($fileName); return strtolower($pathinfo['extension']); } } 数据缓存 uni.setStorage(OBJECT) 异步 uni.setStorageSync(KEY,DATA)同步 uni.getStorage(OBJECT)异步 uni.getStorageSync(KEY)同步 uni.getStorageInfo(OBJECT)异步 uni.getStorageInfoSync()同步 uni.removeStorage(OBJECT)异步 uni.removeStorageSync(KEY)同步 uni.clearStorage() uni.clearStorageSync()同步 设备相关 https://uniapp.dcloud.io/api/system/info 交互反馈 uni.showToast uni.showLoading uni.hideToast uni.hideLoading uni.showModal uni.showActionSheet http://uniapp.dcloud.io/api/system/info 设置导航条 uni.setNavigationBarTitle uni.showNavigationBarLoading uni.hideNavigationBarLoading uni.setNavigationBarColor http://uniapp.dcloud.io/api/ui/navigationbar 导航 uni.navigateTo uni.redirectTo uni.reLaunch uni.switchTab uni.navigateBack http://uniapp.dcloud.io/api/ui/navigate?id=navigateback 下拉树新 onPullDownRefresh 需要在 pages.json 里,找到的当前页面的pages节点,并在 style 选项中开启 enablePullDownRefresh 当处理完数据刷新后,uni.stopPullDownRefresh 可以停止当前页面的下拉刷新。 uni.startPullDownRefresh(OBJECT) 开始下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。 复制 page.json 开启下拉刷新 { "pages": [ { "path": "pages/index/index", "style": { "navigationBarTitleText": "hi uni", "enablePullDownRefresh": true } }, ....... index.vue {{item}} 上拉加载更多复制 {{item}} {{loadingText}} 小程序登陆 http://www.hcoder.net/tutorials/info_1360.html h5+app登陆 http://www.hcoder.net/tutorials/info_1361.html 自定义组件 http://www.hcoder.net/tutorials/info_1362.html
2019-04-30uni-app 常用写法登录 //判断信息是否填写 btn() { if (this.username.length { uni.showToast({ icon: 'none', title: '网络异常,请稍后重试' }
2018-11-30wangeditor 内容修改var E = window.wangEditor var editor = new E('#editor') // 或者 var editor = new E( document.getElemen
2018-08-30KindEditor编辑器第一次获取的到值得解决方案 {$data.addcontent} KindEditor.ready(function(K) { window.editor = K.create('#editor_id'); }); var a
2021-08-26echarts中关系图的使用,以及通过头像的形式展示使用echarts插件实现关系图,如下图所示 代码如下,自己研究 主要就是用了echarts里面的功能,并进行修改,以头像的形式展示关系图 var myChart = echarts.init(doc
2021-12-31网页如何使用ctrl s 保存文章使用网页版写文章有个问题,习惯性的ctrl+s,但是直接打开的保存页面的弹窗,没有实现保存文章的效果那么该如何做呢搜啊搜~~~~~~~~~只要使用一段js即可解决测试了部分浏览器不支持 documen