轉(zhuǎn)發(fā)自:https://blog.csdn.net/a57959735/article/details/108518815霸妹,看到總結(jié)的很好就轉(zhuǎn)發(fā)過來分享下
觸摸事件名稱:
①微信小程序: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慈参,默認為index和item
if判斷:
①微信小程序:<view wx:if="{{isShow}}"></view>
②uni-app:<view v-if="isShow"></view>
src動態(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){}方法中獲取八拱,在此不多提及戏自。
全局數(shù)據(jù)定義:
①微信小程序:globalData:{baseUrl:"www.com"}
②uni-app:this.prototype.baseUrl = "https://www.ccc"
全局數(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ù)
場景類似于填寫表單時某個信息要跳轉(zhuǎn)到其他頁面選擇數(shù)據(jù)后再返回厅篓,并在原填寫表單頁得到并展示剛才選擇的數(shù)據(jù)响驴,當然還有其他相關(guān)的問題能夠運用該方法透且。
①微信小程序:通過getCurrentPages()獲取頁面棧,然后調(diào)用上n個頁面的setData()方法豁鲤,把數(shù)據(jù)存到上n個頁面中秽誊。
// 選擇參數(shù)的頁面
chooseItem(data) {
const pages = getCurrentPages();
const prevPage = pages[pages.length - 3]; //上兩個頁面
prevPage.setData({
? myName: data,
});
wx.navigateBack({ delta: 2 }); //返回到上兩個頁面
},
// 獲取參數(shù)的頁面,即上述的->原填寫表單頁
onShow() {
? const pages = getCurrentPages();
? if (pages[pages.length - 1]) {
? ? const currPage = pages[pages.length - 1]; // 當前頁面
? ? this.brandNum = currPage.data.myName; //這就是傳遞的參數(shù)
? }
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
②uni-app:通過getCurrentPages()獲取頁面棧琳骡,然后使用prevPage.$vm.id = id锅论,把數(shù)據(jù)存到上n個頁面中。
// 選擇參數(shù)的頁面
chooseItem(data) {
? const pages = getCurrentPages();
? const prevPage = pages[pages.length - 3]; //上兩個頁面
? prevPage.$vm.id = id; // 區(qū)別只是這里不同
? uni.navigateBack({ delta: 2 }); //返回到上兩個頁面
},
// 獲取參數(shù)的頁面楣号,即上述的->原填寫表單頁
onShow() {
? const pages = getCurrentPages();
? if (pages[pages.length - 1]) {
? ? const currPage = pages[pages.length - 1]; // 當前頁面
? ? this.brandNum = currPage.data.myName; //這就是傳遞的參數(shù)
? }
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
雖然兩者區(qū)別只有兩行代碼不同最易,且uni-app可以使用微信小程序的方法,但問題總比辦法多炫狱,了解多一點總不會虧藻懒。
————————————————
版權(quán)聲明:本文為CSDN博主「冰谷悠」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議视译,轉(zhuǎn)載請附上原文出處鏈接及本聲明嬉荆。
原文鏈接:https://blog.csdn.net/a57959735/article/details/108518815