觸摸事件名稱:
①微信小程序:bindtap
②uni-app:@click
函數(shù)傳參方式:
①微信小程序:<view bindtap="click" data-id="id"></view>
②uni-app:<view @click="click(id)"></view>
函數(shù)接收參數(shù):
①微信小程序:function(e){ this.setData({ currentId:e.currentTarget.dataset.id }) }
②uni-app:function(id){ this.currentId = id }
for循環(huán):
①微信小程序:<view wx:for="{{currentList}}" wx:for-index="s_index" wx:for-item="s_item"></view>
②uni-app:<view v-for="(s_item,s_index) in currentList"></view>
微信小程序可以不寫wx:for-index和wx:for-item,默認(rèn)為index和item
if判斷:
①微信小程序:<view wx:if="{{isShow}}"></view>
②uni-app:<view v-if="isShow"></view>
src動(dòng)態(tài)接收圖片:
①微信小程序:<image src="{{item.img}}"></image>
②uni-app:<image :src="item.img"></image>
頁面?zhèn)鲄ⅲ?/p>
①微信小程序:<navigator url="/pages/live?id={{item.room_id}}"></navigator>
②uni-app:<navigator :url="'/pages/live?id=' + item.room_id"></navigator>
兩者接收參數(shù)都是在onLoad(options){}方法中獲取,在此不多提及妻顶。
全局?jǐn)?shù)據(jù)定義:
①微信小程序:globalData:{baseUrl:"www.com"}
②uni-app:this.prototype.baseUrl = "https://www.ccc"
全局?jǐn)?shù)據(jù)調(diào)用:
①微信小程序:getApp().globalData.baseUrl
②uni-app:this.baseUrl
數(shù)組拼接:(我真沒有歧視微信小程序的意思)
①微信小程序(ES5):this.setData({ list:this.data.list.concat(res.list) })
②uni-app(ES6):this.list = [...this.list,...res.list];
阻止冒泡:
①微信小程序:<view catchtap="clickTab">我是按鈕</view>
②uni-app:<view @click.stop="clickTab">我是按鈕</view>
api的差別(支付作栗子):
①微信小程序:wx.requestPayment({})
②uni-app:uni.requestPayment({})
小程序的api在uni-app中只需要把wx替換成uni即可使用俱尼。
跨界面獲取選擇的參數(shù)
場景類似于填寫表單時(shí)某個(gè)信息要跳轉(zhuǎn)到其他頁面選擇數(shù)據(jù)后再返回抖韩,并在原填寫表單頁得到并展示剛才選擇的數(shù)據(jù)缤弦,當(dāng)然還有其他相關(guān)的問題能夠運(yùn)用該方法谢鹊。
①微信小程序:通過getCurrentPages()獲取頁面棧浴滴,然后調(diào)用上n個(gè)頁面的setData()方法拓萌,把數(shù)據(jù)存到上n個(gè)頁面中。
// 選擇參數(shù)的頁面
chooseItem(data) {
const pages = getCurrentPages();
const prevPage = pages[pages.length - 3]; //上兩個(gè)頁面
prevPage.setData({
myName: data,
});
wx.navigateBack({ delta: 2 }); //返回到上兩個(gè)頁面
},
// 獲取參數(shù)的頁面升略,即上述的->原填寫表單頁
onShow() {
const pages = getCurrentPages();
if (pages[pages.length - 1]) {
const currPage = pages[pages.length - 1]; // 當(dāng)前頁面
this.brandNum = currPage.data.myName; //這就是傳遞的參數(shù)
}
},
②uni-app:通過getCurrentPages()獲取頁面棧微王,然后使用prevPage.$vm.id = id,把數(shù)據(jù)存到上n個(gè)頁面中品嚣。
// 選擇參數(shù)的頁面
chooseItem(data) {
const pages = getCurrentPages();
const prevPage = pages[pages.length - 3]; //上兩個(gè)頁面
prevPage.$vm.id = id; // 區(qū)別只是這里不同
uni.navigateBack({ delta: 2 }); //返回到上兩個(gè)頁面
},
// 獲取參數(shù)的頁面骂远,即上述的->原填寫表單頁
onShow() {
const pages = getCurrentPages();
if (pages[pages.length - 1]) {
const currPage = pages[pages.length - 1]; // 當(dāng)前頁面
this.brandNum = currPage.data.myName; //這就是傳遞的參數(shù)
}
},
雖然兩者區(qū)別只有兩行代碼不同,且uni-app可以使用微信小程序的方法腰根,但問題總比辦法多激才,了解多一點(diǎn)總不會(huì)虧。
————————————————