In use
wepy
before, probably read the document, and sort out clearlywepy
and原生小程序
,vue
the difference between subsequent post in favor ofwepy
development, to avoid stepping pit.
Norms
- Variables and methods to make use of camel named, and avoid using the $ at the beginning. (Because the internal framework used to avoid confusion)
- Use ES6 development, internal frame is used ES6, ES6 and there are many benefits, it is recommended.
- Use Promise. The default API framework for small programs provided by all performed Promise processing, you can even use the new features directly async / await and other development.
- Event binding syntax changed, similar
vue
(nice ah! Never have to write original wording of the stupid X)bindtap="click"
Replace@tap="click"
catchtap="click"
Replace@tap.stop="click"
bindtap="click" data-index={{index}}
Replace@tap="click({{index}})"
.
Grammar
wepy
It borrows heavily fromvue
the syntax, so mostvue
operations, can be inwepy
use.- For dynamic assignment of property can be used
:attr="value"
the way .wpy
Filescript
,template
,style
three label supportlang
andsrc
property,lang
determine its code compilation process,src
decide whether outreach code existssrc
when the properties and valid, ignore inline code. E.g:<style lang="less" src="page1.less"></style> <template lang="wxml" src="page1.wxml"></template> <script> // some code </script> 复制代码
Component loops rendering differences
In the
wepy
cycle rendering, the components need to use auxiliary labels<repeat>
(personally feel and native of<block>
labels similar role). chestnut:
<repeat for="{{list}}" key="index" index="index" item="item">
<!-- 插入<script>脚本部分所声明的child组件,同时传入item -->
<child :item="item"></child>
</repeat>
复制代码
More interesting is, here
for
,key
,item
,index
all do not need to addwx:
the prefix, and will be easy to write quite right, personally I feel that the practice of prefixing silly, I wrote one of the most annoying place native applets time.
And vue
the methods
differences
WePY
Themethods
property can only be declared page wxml labelsbind
,catch
events can not declare custom methods, whichVue
in usage is inconsistent. Inwepy
the user's custom methods shouldmethods
at the same level. Correct wording is as follows:
methods = {
bindtap () {
let rst = this.commonFunc();
// doSomething
},
}
//正确:普通自定义方法在methods对象外声明,与methods平级
customFunction () {
return 'sth.';
}
复制代码
Default babel
compiler, support for several new features ES6 / ES7 of
- Users can modify wepy.config.js (old version .wepyrc) configuration files, configuration babel familiar environment for development. Enabled by default uses some new features such as promise, async / await (must be manually turned on since WePY 1.4.1) and so on.
Use promise encapsulate native api
Native various callbacks really very stressful, but you can now write the following operations
async onLoad() {
await wepy.login();
this.userInfo = await wepy.getUserInfo();
}
复制代码
Data binding mechanism
wepy
The data binding mechanism andvue
the like, perform dirty checking function ends when the operating cycle , and then automatically updated to render layers. Note that the wording at the end of the function is run cycle, before doing the operation detection updates. So we asynchronous operation, the need to manually call itthis.$apply
method to trigger the check for updates mechanism. example:
setTimeout(() => {
this.title = 'this is title';
this.$apply();
}, 3000);
复制代码
Personally feel that the description is not clear enough, so checked on the net, we need
$apply
the scene as follows:
- When asynchronous update data
- When manually refresh dom
other
- Loading external support
NPM
package (also native support, so nothing highlights) wx.request
Concurrent there is no limit (native also supported)wpyExt
The configuration.wpy
can be changed successfully.vue
, this document will become a suffix.vue
, support the editor will be better