您好,登錄后才能下訂單哦!
排名不分先后,按自己的習慣來的。
總結經驗,不喜勿噴哦~
<view class=" {{currentTab==0 ? 'select' : ''}}" data-current="0" bindtap="swichNav"> tab1</view> <view class=" {{currentTab==1 ? 'select' : ''}}" data-current="1" bindtap="swichNav"> tab2</view> Page({ data:{ // tab切換 currentTab: 0, }, swichNav: function (e) { var that = this; if (this.data.currentTab === e.target.dataset.current) { return false; } else { that.setData({ currentTab: e.target.dataset.current }) } }, })
<view> <text class=" {{currentTab==0 ? 'select' : ''}}" data-current="0" bindtap="swichNav">tab1</text> <text class=" {{currentTab==1 ? 'select' : ''}}" data-current="1" bindtap="swichNav">tab2 </text> <text class=" {{currentTab==2 ? 'select' : ''}}" data-current="2" bindtap="swichNav">tab3 </text> </view> <swiper current="{{currentTab}}" bindchange="bindChange" class='swp' > <swiper-item>頁面1</swiper-item> <swiper-item>頁面2</swiper-item> <swiper-item>頁面3</swiper-item> </swiper> Page({ data:{ currentTab: 0, aheight: '' }, // 滑動切換 bindChange: function (e) { var that = this; that.setData({ currentTab: e.detail.current }); }, //點擊tab切換 swichNav: function (e) { var that = this; if (this.data.currentTab === e.target.dataset.current) { return false; } else { that.setData({ currentTab: e.target.dataset.current }) } }, // swiper 自適應高度 onLoad: function (options) { var that = this wx.getSystemInfo({ success: function (res) { that.setData({ aheight: res.screenHeight }); } }) }, })
<view class="ovf img_box"> <block wx:for="{{img_arr}}" wx:key="{{item.id}}" bindtap="del"> <view class='logoinfo' data-index="{{index}}"> <view class="del"> <image src="http://192.168.2.61/wx_ry/del.png" mode="widthFix" bindtap="deleteImage"></image> </view> <image src='{{item}}' mode="widthFix"></image> </view> </block> <view class="upload"> <image src="http://192.168.2.61/wx_ry/add.png" mode="widthFix" bindtap="upimg"></image> </view> </view> .upload { width: 20%; float: left; margin-top:33rpx ; } .upload image{ width: 100%; } .logoinfo{ width: 20%; float: left; margin-right:2% ; } .del{ width: 20%; float: right; } .del image{ width: 100%; } .logoinfo image{ width: 100%; } page({ data:{ img_arr: [] }, // 圖片上傳 upimg: function () { var that = this; if (this.data.img_arr.length < 3) { wx.chooseImage({ sizeType: ['original', 'compressed'], success: function (res) { that.setData({ img_arr: that.data.img_arr.concat(res.tempFilePaths), }) } }) } else { wx.showToast({ title: '最多上傳三張圖片', icon: 'loading', duration: 3000 }); } }, // 刪除圖片 deleteImage: function (e) { var that = this; var index = e.currentTarget.dataset.index; //獲取當前長按圖片下標 console.log(that.data.img_arr) wx.showModal({ title: '提示', content: '確定要刪除此圖片嗎?', success: function (res) { if (res.confirm) { console.log('點擊確定了'); that.data.img_arr.splice(index, 1); } else if (res.cancel) { console.log('點擊取消了'); return false; } that.setData({ img_arr: that.data.img_arr }); } }) }, // 上傳 upload: function () { var that = this for (var i = 0; i < this.data.img_arr.length; i++) { wx.uploadFile({ url: 'https:***/submit', filePath: that.data.img_arr[i], name: 'content', formData: adds, success: function (res) { console.log(res) if (res) { wx.showToast({ title: '已提交發布!', duration: 3000 }); } } }) } this.setData({ formdata: '' }) }, // 提交 formSubmit: function (e) { console.log('form發生了submit事件,攜帶數據為:', e.detail.value) } })
<scroll-view class="scroll-view_H " scroll-x="true" bindscroll="scroll"> <view class="fxjx_b1" > <view class="listb">1</view> </view> <view class="fxjx_b1" > <view class="listb">2</view> </view> </scroll-view> .scroll-view_H{ white-space: nowrap; height: 600rpx; } .listb{ padding: 25rpx; white-space: normal; }
app.js
//app.js App({ globalData: { userInfo: null, unionid:null, token:'' }, onLaunch: function () { /* 已授權之后,自動獲取用戶信息 */ // 判斷是否授權 wx.getSetting({ success: (res) => { //箭頭函數為了處理this的指向問題 if (res.authSetting["scope.userInfo"]) { console.log("已授權"); // 獲取用戶信息 wx.getUserInfo({ success: (res) => { //箭頭函數為了處理this的指向問題 // this.globalData.isok=true this.globalData.token='ok' var that =this console.log(res.userInfo); //用戶信息結果 wx.getStorage({ key: 'unionid', success(res) { that.globalData.unionid=res.data } }) this.globalData.userInfo = res.userInfo; if (this.userInfoReadyCallback) { //當index.js獲取到了globalData就不需要回調函數了,所以回調函數需要做做一個判斷,如果app.js中有和這個回調函數,那么就對這個函數進行調用,并將請求到的結果傳到index.js中 this.userInfoReadyCallback(res.userInfo); } } }) } else{ console.log("未授權"); wx.removeStorage({ key: 'unionid' }) } } }) } })
wxml
<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="onGotUserInfo" class="btn" data-url='../yzzs/yzzs'> 防疫針助手 </button>
index.js
// pages/index/index.js const app = getApp() Page({ data: { token:'' }, onGotUserInfo: function (e) { var that = this if (this.data.token != 'ok' && app.globalData.token != 'ok') { wx.getSetting({ success: (res) => { //箭頭函數為了處理this的指向問題 if (res.authSetting["scope.userInfo"]) { wx.login({ success: function (data) { console.log('獲取登錄 Code:' + data.code) var postData = { code: data.code }; wx.request({ url: 'https://m.renyiwenzhen.com/rymember.php?mod=xcxlogin&code=' + postData.code + '&nickname=' + e.detail.userInfo.nickName, data: {}, header: { 'content-type': 'application/json' }, success: function (res) { console.log(res.data); that.data.token='ok'; wx.setStorage({ key: "unionid", data: res.data.unionid }) wx.navigateTo({ url: e.target.dataset.url }) }, fail: function () { console.log('1'); } }) }, fail: function () { console.log('登錄獲取Code失敗!'); } }) } } }) } else{ wx.navigateTo({ url: e.target.dataset.url }) } } })
wx.request({ url: 'https://m.renyiwenzhen.com/xcx_ajax.php?action=babylist', //僅為示例,并非真實的接口地址 method: 'post', data: { unionid: uni }, header: { 'content-type': 'application/x-www-form-urlencoded' // 默認值 }, success(res) { // console.log(uni) console.log(res.data) that.setData({ list: res.data.bblist }) } })
全局標題欄
"window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#3EC8C8", "navigationBarTitleText": "乳孕呵護", "navigationBarTextStyle": "white" }
局部標題欄
{ "usingComponents": {}, "navigationBarBackgroundColor": "#fff", "navigationBarTextStyle": "black", "navigationBarTitleText": "附近醫院" }
全局底部欄
"tabBar": { "color": "#e4e4e4", "selectedColor": "#333", "list": [ { "pagePath": "pages/index/index", "text": "發現", "iconPath": "./images/find.png", "selectedIconPath": "./images/finded.png" }, { "pagePath": "pages/his/his", "text": "醫院", "iconPath": "./images/his.png", "selectedIconPath": "./images/hised.png" }, { "pagePath": "pages/stu/stu", "text": "經驗", "iconPath": "./images/stu.png", "selectedIconPath": "./images/stued.png" }, { "pagePath": "pages/my/my", "text": "我的", "iconPath": "./images/my.png", "selectedIconPath": "./images/myed.png" } ] }
1、wxml
<navigator url="/pages/hishome/hishome" open-type="navigate" hover-class="none"> 底部欄沒有的路由 </navigator> <navigator open-type="switchTab" url="/pages/his/his" hover-class="none"> 底部欄有的路由 </navigator>
2、js
go: function (e) { wx.navigateTo({ url: '../eatxq/eatxq?id=' + e.currentTarget.dataset.id + "&name=" + e.currentTarget.dataset.name }) }
<loading hidden="{{onff}}">加載中</loading> <view>頁面</view>
加載完成true
wx.request({ url: 'https://m.renyiwenzhen.com/xcx_ajax.php?action=caneatsearch', method: 'post', header: { 'content-type': 'application/x-www-form-urlencoded' // 默認值 }, data: { search: options.search }, success(res) { that.setData({ list: res.data.fllist, onff: true }) } })
<view class="txt"> <rich-text nodes="{{msg}}" ></rich-text> </view>
利用正則修改收到的數據
wx.request({ url: 'https://m.renyiwenzhen.com/xcx_ajax.php?action=cjdetail', method: 'post', data: { id: options.id }, header: { 'content-type': 'application/x-www-form-urlencoded' // 默認值 }, success(res) { that.setData({ msg: res.data.cjmag.cjxq.replace(/\<p>/g, "<p style='line-height: 24px; font-size:15px;text-align: justify;margin:15px 0;'>") }) } })
1、在根目錄下的utils文件夾里創建一個名為filter.wxs文件 2、寫入自己要定義的條件
var xb=function (v) { var xingb='' if(v==1){ xingb="男寶寶" } else{ xingb="女寶寶" } return xingb } module.exports = { xb:xb }
3、在頁面中引入使用
<wxs src="../../utils/filter.wxs" module="filter" /> <view><text>{{filter.xb(isxb)}}</text></view>
app.js
onLaunch: function () { if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { // 請求完新版本信息的回調 if (res.hasUpdate) { updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已經準備好,是否重啟應用?', success: function (res) { // res: {errMsg: “showModal: ok”, cancel: false, confirm: true} if (res.confirm) { // 新的版本已經下載好,調用 applyUpdate 應用新版本并重啟 updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { // 新的版本下載失敗 wx.showModal({ title: '已經有新版本了喲~', content: '新版本已經上線啦,請您刪除當前小程序,重新搜索打開喲' }) }) } }) } }
我們經常會遇到這種需求:
點擊對應的的tab,這里比如說是A頁。
跳轉到對應項目的頁面,這里比如說是B頁。
A頁:
<view class="project_nab ovf"> <view class="on"> 詳情 </view> <view class="project_item" bindtap="goitem" data-url='jd'>建檔</view> <view class="project_item" bindtap="goitem" data-url='cj'>產檢</view> <view class="project_item" bindtap="goitem" data-url='fm'>分娩</view> </view> goitem:function (e) { wx.navigateTo({ url: '/pages/item/item?url=' + e.target.dataset.url }) },
B頁:
<view class="top1 ovf"> <view class="" ><navigator url="/pages/hishome/hishome" open-type="navigate">詳情</navigator></view> <view class=" {{currentTab==0 ? 'select' : ''}}" data-current="0" bindtap="swichNav"> 產檢 </view> <view class=" {{currentTab==1 ? 'select' : ''}}" data-current="1" bindtap="swichNav"> 建檔 </view> <view class=" {{currentTab==2 ? 'select' : ''}}" data-current="2" bindtap="swichNav"> 分娩 </view> </view> onLoad: function (options) { var that = this; console.log(options.url) if (options.url === 'cj') { that.setData({ currentTab: '0', btn: '產檢', set: 'cj' }); } else if (options.url === 'jd') { that.setData({ currentTab: '1', btn: '建檔', set: 'jd' }); } else { that.setData({ currentTab: '2', btn: '分娩', set: 'fm' }); } }
總結
以上所述是小編給大家介紹的微信小程序實用代碼段,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。