微信小程序转uni-app时常见的语法变化


  • 属性绑定从 attr="{{ a }}",改为 :attr="a";从 title="复选框{{ item }}" 改为 :title="'复选框' + item"
  • 事件绑定从 bind:click="toggleActionSheet1" 改为 @click="toggleActionSheet1",目前支付宝小程序不支持 vue 的事件绑定方式,具体参考:支付宝小程序组件事件监听示例
  • 阻止事件冒泡 从 catch:tap="xx" 改为 @tap.native.stop="xx"
  • wx:if 改为 v-if
  • wx:for="{{ list }}" wx:key="{{ index }}" 改为v-for="(item,index) in list"

1.官方推荐的正则公式:

1 str = str.replace(/bindtap/g, '@onclick');  
2 str = str.replace(/wx:if/g, 'v-show');  
3 str = str.replace(/src=\'\{\{/g, ":src='");  
4 str = str.replace(/wx\:key=\"\*this\"/g, ' ');  
5 str = str.replace(/wx\:key\=\"index\"/g, ' ');  
6 str = str.replace(/wx:for="{{/g, v-for= "(item,index) in ');  
7 str = str.replace(/bindinput/g, '@input'); 

详细内容见:https://ask.dcloud.net.cn/article/35786