原生小程序转mpvue踩坑总结

编程入门 行业动态 更新时间:2024-10-18 23:24:20

原生小<a href=https://www.elefans.com/category/jswz/34/1771429.html style=程序转mpvue踩坑总结"/>

原生小程序转mpvue踩坑总结

坑一:mpvue开发小程序时候,要添加静态本地图片

  • 报错:

VM14878:2 Failed to load local image resource /images/bg.png 
the server responded with a status of 404 (HTTP/1.1 404 Not Found)

*解决方法:将放图片的文件夹放在static文件夹里,static是专门用来放静态文件的


坑二:data中每个键值对,:后面要有空格;

  • 报错:

✘  Missing space before value for key 'tabs'
srcpagestestindex.vue:22:12

坑三:字符串必须以单引号包括;

  • 报错:

✘  Strings must use singlequote
srcpagestestindex.vue:23:9


坑三:定义函数时,(括号)前(后)都要有空格

  • 报错:
    ✘  Missing space before function parentheses

srcpagestestindex.vue:31:23


坑四:函数中各语句间不用加分号


坑五:button按钮获取用户信息,weui里好像不对;

直接为button添加点击事件,设置其open-type和lang,在函数回调里即可获得用户信息

代码如下:

<template><div><button v-on:click="click" open-type="getUserInfo" lang="zh_CN">按钮</button></div>
</template><script>export default {methods: {click: function (e) {console.log('userInfo', e)}}
}
</script>

表单事件的提交与重置

在form上绑定@submit(@reset)="dddd",在button上设置其form-type="submit/reset"执行相关操作

数据结构看console打印的结果

如果form或button忘记上述设置,其回调函数中返回的是鼠标的点击事件
若form绑定的不是@submit,而是@click,则点击表单内任一元素均会提交表单


在使用sublime时,不要使用tab,这会使其缩进出现问题!!!


Trailing spaces not allowed

*表示你在该行有多余的空格


分享功能不能写在components中,要写在父组件里

否则报错:

Cannot read property 'apply' of null;at pages/commit-done/index page onShareAppMessage function
TypeError: Cannot read property 'apply' of null


使用第三方框架,坑较多,在允许的情况下,可使用原生组件

书写规范问题

报错

✘    Infix operators must be spacedsrc\pages\hzw_text\index.vue:34:23for (var i = 1; i <4; i++) {

意思是4前面需要一个空格

使用mpvue自定义左边胶囊按钮时,由于单位不充一问题,自定义胶囊和系统胶囊在不同型号手机上不同对齐

原因分析:系统胶囊使用pt为单位,但mpvue转小程序时,px单位转为rpx,会自适应变化;
解决方法: 使用绝对单位 pt

更多推荐

原生小程序转mpvue踩坑总结

本文发布于:2024-02-05 08:29:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1673806.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   mpvue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!