Wepy framework
it is a framework class Vue, Vue draws on code style, and Vue itself has nothing to do.
mpVue frame
which is a frame from the core through the secondary development of code for the entire Vue formed, it is equivalent to forming Vue itself, increase the ability to develop small micro-channel program.
The difference between the three Figure:
Need some attention when using mpVue:
1. In the template, the dynamic insertion of v-html HTML instructions not available
This is well understood, the interface is not based applet BOM / DOM browser, so can not dynamically insert HTML snippets directly in the interface template to display.
The way, if there is a small fragment insert html procedures in demand how to do? Can use
These limitations include bis bracket expression syntax {} {} function is 2. In the template, for data binding
Vue itself within the template double-bracket syntax, we can compare the process to enrich bind variables, such as:
- You can call a function in methods, such as:
<template>
<div>{{ formatMessage(msg) }}</div>
</template>
<script>
export default {
data() {
return {
msg: "Hello,World"
}
},
methods: {
formatMessage(str) {
return str.trim().split(',').join('#')
}
}
}
</script>
- If the variable is an object, you can also call the object's member method
<div>{{ msg.trim().split(',').join('#') }}</div>
- Filters can be used to process variables, the most useful of the scene data be formatted
<div>{{ msg | format }}</div>
These useful features, in mpvue in, all I remember is not used Oh! ! !
We can only use double brackets in some simple arithmetic operators (+ - *%:? == ===> <[]!.).
Consider using computed attribute (computed) do.
3. In the template, in addition to the event listener, the other place can not function under the methods call
Available alternatives: Calculated Properties
4. in the template does not support a direct binding to the target class or style attributes
The best solution: Calculated Properties
<template>
<div :class="classStr"></div>
</template>
<script>
export default {
data() {
return {
classObject: {
active: true,
'text-danger': false
}
}
},
computed: {
classStr() {
let arr = []
for (let p in this.classObject) {
if (this.classObject[p]) {
arr.push(p)
}
}
return arr.join(' ')
}
}
}
</script>
5. In the template, nested v-for, index must be specified index
Usually, we nested loop when rendered in Vue array of templates, usually looks like this:
<template>
<ul v-for="category in categories">
<li v-for="product in category.products">{{product.name}}</li>
</ul>
</template>
但在mpvue中使用这种嵌套结构的v-for时,则必须每层的v-for上都给出索引,且索引需取不同名字:
<template>
<ul v-for="(category, index) in categories">
<li v-for="(product, productIndex) in category.products">{{product.name}}</li>
</ul>
</template>
6. 事件处理中的注意点
在mpvue中,一般可以使用Web的DOM事件名来绑定事件,mpvue会将Web事件名映射成对应的小程序事件名,对应列表如下:
// 左侧为WEB事件 : 右侧为对应的小程序事件
{
click: 'tap',
touchstart: 'touchstart',
touchmove: 'touchmove',
touchcancel: 'touchcancel',
touchend: 'touchend',
tap: 'tap',
longtap: 'longtap',
input: 'input',
change: 'change',
submit: 'submit',
blur: 'blur',
focus: 'focus',
reset: 'reset',
confirm: 'confirm',
columnchange: 'columnchange',
linechange: 'linechange',
error: 'error',
scrolltoupper: 'scrolltoupper',
scrolltolower: 'scrolltolower',
scroll: 'scroll'
}
除了上面的之外,Web表单组件<input>
和<textarea>
的change事件会被转为blur事件。
然后,像keydown、keypress之类的键盘事件也没有了,因为小程序没有键盘,所以不需要这些事件。
7. 对于表单,请直接使用小程序原生的表单组件
其他注意事项
另外,在Vue开发Web应用的时候,通常使用vue-router来进行页面路由。但是在mpvue小程序开发中,不能用这种方式,请使用标签和小程序原生API wx.navigateTo等来做路由功能。
还有就是请求后端数据,我们通常在Web开发中使用axios等ajax库来实现,但是在小程序开发中也是不能用的,也请使用小程序的原生API wx.request等来进行。
微信小程序的UI组件库
- WeUI
- iView
- ZanUI
- MinUI
- Wux
- ColorUI