mpvue开发微信小程序,在vue中支持,但在mpvue中不支持的地方

mpvue是使用vue.js开发微信小程序的前端框架,这篇文章主要说一下,

开发微信小程序过程中遇到的在vue中支持,但在mpvue中不支持的地方:

(1)不支持v-html。因为小程序没有dom的概念。

(2)不支持部分javascript渲染表达式,如:

<!--方法的调用-->
<p>{{getDesc(song)}}</p>
<!--过滤器-->
<p>{{ createTime | format}}</p>
<!-- v-if指令中调用函数  -->
<div v-if="getErrorNum() > 0  && code == 10001" class="error">{{ errorMsg }}</div>
<!--运算-->
<div>{{ msg.trim().split(',').join('#') }}</div>

(3)不支持直接绑定一个对象到styleclass属性上

<template>
  <div :class="classObject" :style="styleObject"></div>
</template>

<script>
export default {
  data() {
    return {
      classObject: {
        active: true
      },
      styleObject: {
        'width': '100px'
    }
  }
}
</script>

(4)img标签中,不能设置宽度高度,例如:width="200"  height="200"

(5)css中background-image里的url只能是服务器上的地址,不能是本地图片地址。

(6)在跳转之后进入的页面,或者pages目录下的vue文件,不要使用created()。会获取不到mapGetters数据。用async onLoad()代替。

(7)不支持的插件:jsonp / vue-lazyload / better-scroll / vue-awesome-swiper 等等

(8)不支持

v-show(可用v-if代替)

transition

keep-alive

(9)组件命名与小程序的冲突,例如:<loading></loading>

产生的bug就是,title的值取不到

<template>
  <div class="loading">
    <p class="desc">{{title}}</p>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      title: {
        type: String,
        default: '正在载入…'
      }
    }
  }
</script>

(10)不能使用vue-router,可以用a标签、wx.navigateTo、wx.redirectTo等等来代替

(11)vuex的使用,需要补充一点:将store对象通过$store属性添加到vue原型上,即:Vue.prototype.$store = store

  目前发现的就是以上几点,如果有说的不对的地方,欢迎指出,一起探讨~

猜你喜欢

转载自blog.csdn.net/qq_32678401/article/details/81744424