mpvue 注意事项

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_33871182/article/details/102742559

1、页面跳转,注意是普通跳转navigateTo还是底部导航跳转 switchTab

starQuestion(){
const url = ‘…/subject/main’
// switchTab navigateTo
wx.switchTab({ url })
},

2、变量 图片 文字 引入组件

<img :src="item.ad_url" alt="">
<toast :message="msg" :visible.sync="visible" position="center">{{tips}}</toast>

3.事件

如 bindchange=“eventName” 事件,需要写成 @change=“eventName”

bindgetuserinfo 要写成 @getuserinfo,bindcontact 要写成 @contact,bindgetphonenumber 要写成 @getphonenumber,binderrror 要写成 @errror

4.循环语句

v-for
v-for里边必须加:key(双重循环如下)

<div class='item-list' v-for="(item, index) of list" :key="index">
<div class='title'>{{item.name}}</div>
<div class='flex flex-wrap'>
<div class='item-box flex flex-justify-center flex-align-center' v-for="(items, subIndex) of item.itemlist" :key="subIndex" >{{items}}</div>
</div>
</div>

5.触发事件取值问题
小程序:event.detail = {value: value}
在 mpvue中要这样写:event.mp.detail = {value: value}

6.对于一些回调函数,比如getuserinfo,在原生小程序中,获取信息为:e.detail,但在mpvue中,获取方式为:e.mp.detail。

7.文件夹首字母不能大写

8.在 input 和 textarea 中 change 事件会被转为 blur 事件

猜你喜欢

转载自blog.csdn.net/qq_33871182/article/details/102742559