本文并非入門向介紹文章,適合有一定前端基礎的開發者閱讀。
開發整體體驗
首先我們回憶下最開始公測時官方開發工具是個什么樣子:
前兩個問題開發工具已經很好解決了,最后的問題在正式版發布后我也沒再碰到過了,可以說已經比較穩定了。
一些開發建議
// 以下的用法是不行的
this.setData{obj, ...data}
// 參數 spread 是可以的
function f(x, ...y) {
// y is an Array
return x * y.length;
}
page {
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
}
遇到的一些問題及解決辦法
export function formatHTML(html) {
html = html.replace(/<style([\s\S]*?)<\/style>/gi, '');
html = html.replace(/<script([\s\S]*?)<\/script>/gi, '');
html = html.replace(/<\/div>/ig, '\n');
html = html.replace(/<\/li>/ig, '\n');
html = html.replace(/<li>/ig, ' * ');
html = html.replace(/<\/ul>/ig, '\n');
html = html.replace(/<\/p>/ig, '\n');
html = html.replace(/<br\s*[\/]?>/gi, "\n");
html = html.replace(/<[^>]+>/ig, '');
html = html.replace(/\n{2,}/g, '\n\n')
html = html.replace(/\n+$/g, '')
html = html.replace(/ /g, ' ')
return html
}
export function queue (fns, count) {
return new Promise(function(resolve, reject) {
let a = fns.slice(0, count)
let b = fns.slice(count)
let l = fns.length
let runs = 0
if (fns.length == 0 ) return resolve()
for (let fn of a) {
fn().then(() => {
runs += 1
if (runs == l) return resolve()
let next = function () {
let fn = b.shift()
if (!fn) return
return fn().then(() => {
runs += 1
if (runs == l) return resolve()
return next()
}, reject)
}
return next()
}, reject)
}
})
}
response = RestClient.post("https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=#{token}", {
path: "pages/affiliate/index?id=#{id}&#{code}",
width: 430
}.to_json)
最后,開發本身對于小程序而言只能算是剛開始的一小步,由于微信的流量控制,后續的鋪碼之路任重道遠。
以上,不希望對您有所幫助,因為小程序的開發實在不是一件可以讓人愉悅的事:)