ő̖_l̳ҕlԔ
ő̖(С̖·Q)Kځ!
Ŀǰ߀̎ڃȜyAΣֻՈ˲IcyشҶPđ̖KΑBʲô?ӌһ̖ɞ顸С?
҂rһεĵߵČʾһ_l^̰ɡ(˾Ŀ߀ܷaͽ؈D߅Ӱ߅͵͵oҌ̡̳xƬСFṩķ̖@gԲĽ̳̾áƬСĹ̖LӸ°l😄)
OKұM쿴@ݽ̳̣עҪҹ!_ʼϣһܰlһƪ̳!ӛ_ʼ!׃!
_ʼ_l̖֮ǰȿٷġС̳̰!(݁ŹٷġС_lָ)
ęnһһС֙CwԓСČHЧ@С퓌@ʾgӭZԼǰÑ^c^_в鿴ǰСĆ־
1. @ȡС AppID
҂Ҫһ̖ܿԓęn҂ѽՈㄓһ̖עⲻֱʹ÷̖ӆ̖ AppID ṩĎ̖䛾ͿھWվġOá-_lOá鿴С AppID
ע⣺҂עԕrĹT̖֙CwԓСô҂߀Ҫ_lߡڡÑ - _lߡģKҪwԓС̖̳ĬJעԎ̖wʹùT̖
2. Ŀ
҂Ҫͨ^_l߹Сʹa
_l߹߰bɺ_ʹŒߴaxĿī@ȡ AppIDOһĿQ(СQ)硸ҵĵһĿxһصļAa惦Ŀc½ĿͿˡ
鷽W˽СĻaYڄ^xıļAǂļA_l߹ߕʾǷҪһ quick start Ŀxǡ_l߹ߕ҂_lĿһε demo
Ŀɹ҂ͿcԓĿM벢_l߹߽cȌڡԲ鿴;҂Ĵaڡ{ԇԜyԇaģMСſ͑ЧڡĿl͵֙CA[HЧ
3. a
c_l߹Ȍġ҂Կ@ĿѽʼһЩεĴaļPIҲDZزٵģ app.jsapp.jsonapp.wxss @.js Y_ļ.json Yļļ.wxss YǘʽļСxȡ@ЩļС
҂˽@ļĹܣԼ^_lԼС
app.js С_a҂@ļбO ̎Сںȫ׃{ MINA ṩS API籾ͬ惦ͬxȡؔ
//app.jsApp({
onLaunch function () {
// { API ıؾЫ@ȡ var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs' logs)
}
getUserInfofunction(cb){
var that = this;
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
// {õ䛽ӿ wx.login({
success function () {
wx.getUserInfo({
success function (res) {
that.globalData.userInfo = res.userInfo;
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
});
}
}
globalData{
userInfonull }
})
app.json njСȫ҂@ļСЩMɣСĴ ɫÌlʽĬJ}עԓļκעጡ
/**app.json*/{
"pages"[
"pages/index/index"
"pages/logs/logs" ]
"window"{
"backgroundTextStyle""light"
"navigationBarBackgroundColor" "#fff"
"navigationBarTitleText" "WeChat"
"navigationBarTextStyle""black" }
}
app.wxss СĹʽ҂M class ֱʹ app.wxss ĘʽҎt
/**app.wxss**/.container {
height 100%;
display flex;
flex-direction column;
align-items center;
justify-content space-between;
padding 200rpx 0;
box-sizing border-box;
}
3.
@̳҂Ѓɂindex logs gӭ퓺С־չʾ pages Ŀ¡Сеÿһġ· + Ҫ app.json pages pages еĵһС
ÿһСͬ·ͬĂͬYļĽM磺index.jsindex.wxmlindex.wxssindex.json.js Yļ_ļ.json Yļļ.wxss Yǘʽļ.wxml YļYļ
index.wxml ĽYļ
<!--index.wxml--><view class="container"> <view bindtap="bindViewTap" class="userinfo"> <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image> <text class="userinfo-nickname">{{userInfo.nickName}}</text> </view> <view class="usermotto"> <text class="user-motto">{{motto}}</text> </view></view>
ʹ <view/><image/><text/> Yͽ̎
index.js _ļ@ļ҂ԱO ̎ں@ȡС̎픵푑潻¼ȡ
//index.js// @ȡÌvar app = getApp()
Page({
data {
motto 'Hello World'
userInfo {}
}
// ¼̎ bindViewTap function() {
wx.navigateTo({
url '../logs/logs' })
}
onLoad function () {
console.log('onLoad')
var that = this // {ÑÌķ@ȡȫ֔ app.getUserInfo(function(userInfo){
// that.setData({
userInfouserInfo
})
})
}
})
index.wxss Ęʽ
/**index.wxss**/.userinfo {
display flex;
flex-direction column;
align-items center;
}.userinfo-avatar {
width 128rpx;
height 128rpx;
margin 20rpx;
border-radius 50%;
}.userinfo-nickname {
color #aaa;
}.usermotto {
margin-top 200px;
}
ĘʽǷDZҪġʽrĘʽеĘʽҎtӯBw app.wxss еĘʽҎtָĘʽҲĽYļֱʹ app.wxss ָĘʽҎt
index.json ļ
ļǷDZҪġļrԓw app.json window ͬ]ָļtԓֱʹ app.json еĬJá
logs Y
<!--logs.wxml--><view class="container log-list"> <block wxfor-items="{{logs}}" wxfor-item="log"> <text class="log-item">{{index + 1}}. {{log}}</text> </block></view>
logs ʹ <block/> Ƙ˺Ma <block/> ʹ wxfor-items logs logs ѭhչ_c
//logs.jsvar util = require('../../utils/util.js')
Page({
data {
logs []
}
onLoad function () {
this.setData({
logs (wx.getStorageSync('logs') || []).map(function (log) {
return util.formatTime(new Date(log))
})
})
}
})
\нY£
4. ֙CA[
_l߹ȲˆΙxĿcA[ߴaſ͑w
ĿǰA[ςПoFҪȴŹٷһ
ҊŹٷo_lָ߀dzܶ༚aܶ]_չʾԽ͵չʾĕr!_l̳ʽ_ʼ!
һ£ʂ乤
Üʂ乤Ҫ_lһő̖ҪǰŵĹٷWվd_l߹
1. d_l߹_ԓ棺
2. c½ web+ĿSF®棺
3. ԓȵĸ헃Ҫע——
AppIDչٷጁ
Appname ĿļAQ㌢顸ABCt֮ȫĿݾڡ/ABC/…Ŀ
_lĿ䛣ĿڱصĿ䛡
עٴΏ{͈F꠳ɆTͬ_lԓĿthゃʹͬӵĿQĿԴ_fͬ_lĽyһԡ֮ǰĿt^cσݽ٘
4. ʂ乤ȫɺc½Ŀoc_
5. ψDʾ˿_l߹ѽԄӘһʼ demo ĿԓĿȰһőĿ߂ĻݺͿܽYcĿQ(Dмcards)MԓĿܿĿĻܘˣ
ڶ£Ŀ
ĿǰÑȺwdzƳ̖Ժ𱬳̶ȴҶõҲͬƄ h5 ĸٰlչS̖IյԽԽs̖FڵĵҲǡ̎҂FwһɴęnlFṩo_lߵķʽҲڰlȫĸ׃IJ DOM Dṩһ^ߌFܶ h5 ڹ̖yFĹc hybrid _lͬ hybrid _lķʽǣ_ŵĽӿڸ֔Y횲ṩo҂ĽMⲿĿܺͲ@ʹ_lȫÓx DOM_l˼D׃ܴ
ĺĹܷdzҪ˽\̡
ڣ
index.js棺
_l߹ Console Կ
console Կ App Launch-->App Show-->onload-->onShow-->onReady
app Ćc@ʾapp Ć app.js M뵽ļd@ʾȵ
@̎ܶ|d֮ĶԌFȵȡ
·ɣ
·Ŀ_lһֱǂc@䌍Ō·ɵĽBҊ·ɷ潛^ܺõķbҲṩD
wx.navigateTo(OBJECT)ǰDÃȵijʹwx.navigateBackԷصԭ
wx.redirectTo(OBJECT)P]ǰDÃȵij档
wx.navigateBack()P]ǰ棬ǰһ
@ʹ·ɷŷbĺܺ_l߸ȥ·ɣܶ·ɷúܷ
M
˴ڽMṩҲǷdzȫϝMĿʶ_lٶȷdz_lǰJg[״_lЧʕܺá
κⲿԼϟoʹԭ js Ҳyʹãǰ҂ js Ҳȫһ dom ʽڣő̖˴εļܘDzSκ domBǰ҂TʹõĄӑBOõrem.jsҲDzֵ֧
˴߀ṩ WebSocketͿֱ죬_lĿgdz
̖҂lF_l̖MYӻ´ꑿdzM@ϲIJʵҁlF
_ʼһЩεĴa!
1. ҵĿļAľ档@ʹ Sublime Text ԸԼ_lTxԼϲgľ
2. ҪԼĿ{ĿYڷĿcard_courseĿҪˡtabBarԼԓõһЩļ
3. ʾĿġtabBar傀ˆΰo
4. ҵapp.jsonļÁ@傀ˆڴaҵ”tabBar”
ԸHĿУ
ColorǵײwɫselectedColorГQԓɫborderStyleГQˆһlɫbackgroundColorǵײˆΙڱɫ^hһһ{ԇ鿴Чӡ
“list”µĴaηãS
”pagePath”֮ļ.wxmlY[@_laԻһc——㹝saĕrgolļY
”iconPath”δ@@ʾĈD·@ɂ·ֱǾWjD
”selectedIconPath”鮔ǰ@ʾD·ȥȥ֮ĬJ@ʾ顸”iconPath”ĈD
”Text”}Ҳȥȥ֮@ʾDˣֻȥһԓλÕռ
ע⣺ŵĵײˆ֧(傀 icons)OӋőõ UI ͻܘrҪAȿ]òˆΙڵŲ
5. ϴaҎtʾĿĻܘㅢ
6. Jsonļúúcard_courseĻYψDʾҪӼԕrhȱٵӼtҪ½hӼrӛ혎zһ¡app.jsonPǷѽһh
ע⣺҂˽h½һwxmlļͬrьġjs͡wxssļһ½ãő̖cǽһwxmlļrͬrͬĿҵͬļġjs͡wxssļԡjsļ輰rڡapp.jsonAúá
wxmlrő̖ṩĽӿھa־ǰġdiv҂FھáviewɡҪӼrԸṩĽӿx
ʹáclassOØʽid@]ʲô̎Ҫdom
7. ʾĿ퓵ġwxmlaĈDоͿԿFһadz
8. WxssļĘʽļҲֱ挑ʽʾвõ뷽ʽ
9. ĴaˢһԿδOġview˺ֱ׃˷ɫ
ע⣺ġwxml͡wxssµăݺֱ F5 ˢ¾ֱӿЧġjstc؆oܿЧ
10. ʽڡapp.wxssֱá
11. JsļҪڡapp.jsonļġ”page”AúĿYʾĿеġindexͬĿ½Ăļw£
^ϲEе傀ײˆξȫꮅ
YӍ