这篇文章主要介绍微信小程序开发中会遇到的问题有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
data数据更新
-
直接对this.data进行赋值,是无法更新视图绑定的数据的,会造成数据不一致
-
需要使用this.setData更新
this.data.key = value
this.setData({
key: value
})
require
-
暂时不支持绝对路径
const util = require('../../utils/util.js')
background-image
-
不能使用静态文件,只能使用base64和网络图片
-
可以用<img>解决
background: #fff url(data:image/jpeg;base64,***) <image class="logo" src="/images/logo.png" mode="cover"></image>
组件样式
-
app.wxss 的样式不能应用到组件内部
-
可以按需引用 import: “”
@import "/app.wxss";
textarea
-
textarea默认样式有固定宽度
事件传参
-
模板里面事件不能传参
-
使用event.currentTarget.dataset获取
<view id="tapTest" data-hi="WeChat" bindtap="tapName"> Click me! </view>
Page({
tapName(event) {
console.log(event.currentTarget.dataset.hi)
}
})
animation
-
animation不能直接绑定中组件上
-
外面包裹一层<view>
<view animation={{animation}}>
<my-component></my-component>
</view>
checkBox
-
checkbox-group绑定的bindChange事件,我们中点击checkbox事件会向上冒泡,导致外层也被点击
-
checkBox外面包一层view,给view添加一个catch事件
<checkbox-group bindchange="checkboxChange">
<view bindtap="bindTap">
<view catchtap='catchTap'">
<checkbox value="{{value}}" checked="{{checked}}"/>
</view>
</view>
</checkbox-group>
以上是“微信小程序开发中会遇到的问题有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注本站行业资讯频道!