黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

Mini Program

Mini Program

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

建议使用全新的邮箱,没有注册过其他小程序或者公众号的。

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

APPID

APPID

????

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

vs code

vs code

微信小程序编辑工具

微信小程序编辑工具

vs code

vs code

微信编辑工具

微信编辑工具

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

WXML

WXML

WXSS

WXSS

JavaScript

JavaScript

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

app.json

app.json

page.json

page.json

注意:配置文件中不能出现注释

app.json

app.json

app.json

app.json

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

pages

pages

window

window

page.json

page.json

page.json

page.json

app.json

app.json

window

window

app.json

app.json

window

window

{

"pages":[

 "pages/index/index",

 "pages/logs/logs"

],

"window":{

 "backgroundTextStyle":"light",

 "navigationBarBackgroundColor": "#fff",

 "navigationBarTitleText": "WeChat",

 "navigationBarTextStyle":"black"

}

}

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

#000000

#000000

black

black

white

white

dark

dark

light

light

true

true

app.json

app.json

sitemap.json

sitemap.json

<view> {{ message }} </view>

Page({

data: {

 message: 'Hello MINA!'

}

})

<view id="item-{{id}}"> </view>

Page({

data: {

 id: 0

}

})

<checkbox checked="{{false}}"> </checkbox>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

item

item

wx:for

wx:for

item

item

index

index

wx:for

wx:for

index

index

wx:key

wx:key

wx:key

wx:key

string

string

<view hidden="{{flag ? true : false}}"> Hidden </view>

<view> {{a + b}} + {{c}} + d </view>

Page({

data: {

 a: 1,

 b: 2,

 c: 3

}

})

<view wx:if="{{length > 5}}"> </view>

<view>{{"hello" + name}}</view>

Page({

data:{

 name: 'MINA'

}

})

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

*this

*this

item

item

wx:if="{{condition}}"

wx:if="{{condition}}"

wx:if

wx:if

hidden

hidden

list:[{id:0,name:"炒饭"},{id:1,name:"炒面"}]

wx:key="id"

list:[1,2,3,4,5]

wx:key="*this"

<view wx:for="{{array}}" wx:key="id">

{{index}}: {{item.message}}

</view>

Page({

data: {

 array: [{

  id:0,

  message: 'foo',

 }, {

  id:1,

  message: 'bar'

 }]

}

})

<block wx:for="{{[1, 2, 3]}}" wx:key="*this" >

<view> {{index}}: </view>

<view> {{item}} </view>

</block>

<view wx:if="{{false}}">1</view>

<view wx:elif="{{true}}">2</view>

<view wx:else>3</view>

<view hidden="{{condition}}"> True </view>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

wx:if

wx:if

bindtap

bindtap

bindinput

bindinput

bindchange

bindchange

value

value

WeiXin Style Sheets

WeiXin Style Sheets

WXML

WXML

rpx

rpx

<input bindinput="handleInput" />

Page({

// 绑定的事件

handleInput: function(e) {

 console.log(e);

 console.log("值被改变了");

}

})

<input bindinput="handleInput(100)" />

<input bindinput="handleInput" data-item="100" />

handleInput: function(e) {

 // {item:100}

 console.log(e.currentTarget.dataset)

  

 // 输入框的值

 console.log(e.detail.value);

}

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

rpx

rpx

750rpx

750rpx

iPhone6

iPhone6

375px

375px

750rpx = 375px = 750物理像

750rpx = 375px = 750物理像

1rpx = 0.5px = 1物理像素

1rpx = 0.5px = 1物理像素

750rpx = pageWidth px

750rpx = pageWidth px

1px=750rpx/pageWidth

1px=750rpx/pageWidth

px

px

750/pageWidth rpx

750/pageWidth rpx

@import

@import

*

*

/** common.wxss **/

.small-p {

padding:5px;

}

/** app.wxss **/

@import "common.wxss";

.middle-p {

padding:15px;

}

*{

 margin:0;

 padding:0;

 box-sizing:border-box;

}

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

.intro

.intro

#firstname

#firstname

view

view

view,

view,

checkbox

checkbox

view::after

view::after

view::before

view::before

less

less

wepy

wepy

mpvue

mpvue

taro

taro

vscode

vscode

easy less

easy less

less

less

index.less

index.less

view,text,rich

view,text,rich

text,button,image,navigator,icon,swiper,radio,checkbox。

text,button,image,navigator,icon,swiper,radio,checkbox。

div

div

 "less.compile": {

   "outExt":    ".wxss"

 }

<view hover-class="h-class">

点击我试试

</view>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

<text selectable="{{false}}" decode="{{false}}">

 普&nbsp;通

</text>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

微信内置轮播图组件

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

滑块

导航组件 类似超链接标签

富文本标签

v

v

html

html

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

// 1  index.wxml 加载 节点数组

<rich-text nodes="{{nodes}}" bindtap="tap"></rich-text>

// 2 加载 字符串

<rich-text nodes='<img

src="https://developers.weixin.qq.com/miniprogram/assets/images/[email protected]

ng" alt="">'></rich-text>

 

// index.js

 

Page({

data: {

 nodes: [{

  name: 'div',

  attrs: {

   class: 'div_class',

   style: 'line-height: 60px; color: red;'

  },

  children: [{

   type: 'text',

   text: 'Hello&nbsp;World!'

  }]

 }]

},

tap() {

 console.log('tap')

}

})

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

nodes

nodes

字符串

字符串

标签节点数组

标签节点数组

nodes

nodes

String

String

rich

rich

text

text

attrs

attrs

name

name

HTML

HTML

img

img

<button

type="default"

size="{{defaultSize}}"

loading="{{loading}}"

plain="{{plain}}"

>

default

</button>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

appid

appid

appid

appid

客服

客服

微信

微信

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

Page({

data: {

 iconSize: [20, 30, 40, 50, 60, 70],

 iconType: [

  'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel',

'download', 'search', 'clear'

 ],

 iconColor: [

  'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'

 ],

}

})

<view class="group">

<block wx:for="{{iconSize}}">

 <icon type="success" size="{{item}}"/>

</block>

</view>

<view class="group">

<block wx:for="{{iconType}}">

 <icon type="{{item}}" size="40"/>

</block>

</view>

<view class="group">

<block wx:for="{{iconColor}}">

 <icon type="success" size="40" color="{{item}}"/>

</block>

</view>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

可以通过 color属性来修改颜色

可以通过 color属性来修改颜色

类似vue或者react中的自定义组件

类似于页面,一个自定义组件由

json

json

wxml

wxml

wxss

wxss

js

js 4个文件组成

components/myHeader

components/myHeader

myHeader

myHeader

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

json

json

myHeader.json

myHeader.json

wxml

wxml

wxss

wxss

slot

slot

myHeader.wxml

myHeader.wxml

wxss

wxss

注意:在组件wxss中不应使用ID选择器、属性选择器和标签名选择器。

myHeader.wxss

myHeader.wxss

js

js

Component()

Component()

myHeader.js

myHeader.js

{

"component": true

}

<!-- 这是自定义组件的内部WXML结构 -->

<view class="inner">

{{innerText}}

 <slot></slot>

</view>

/* 这里的样式只应用于这个自定义组件 */

.inner {

color: red;

}

Component({

properties: {

 // 这里定义了innerText属性,属性值可以在组件使用时指定

 innerText: {

  // 期望要的数据是 string类型

  type: String,

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

json

json

index.wxml

index.wxml

Component

Component

Component

Component

  value: 'default value',

 }

},

data: {

 // 这里是一些组件内部数据

 someData: {}

},

methods: {

 // 这里是一个自定义方法

 customMethod: function(){}

}

})

{

// 引用声明

"usingComponents": {

// 要使用的组件的名称   // 组件的路径

 "my-header":"/components/myHeader/myHeader"

}

}

<view>

<!-- 以下是对一个自定义组件的引用 -->

<my-header inner-text="Some text">

 <view>用来替代slot的</view>

 </my-header>

</view>

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

properties

properties

setData

setData

{{tabs}}

{{tabs}}

tabItems

tabItems

onMyTab

onMyTab

bindmytap

bindmytap

mytap

mytap

triggerEvent

triggerEvent

事件名

事件名

detail

detail

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

this.selectComponent("#tabs")

this.selectComponent("#tabs")

// page.wxml

<tabs tabItems="{{tabs}}" bindmytap="onMyTab" >

内容-这里可以放插槽

</tabs>

// page.js

data: {

 tabs:[

  {name:"体验问题"},

  {name:"商品、商家投诉"}

 ]

},

onMyTab(e){

 console.log(e.detail);

},

// com.wxml

<view class="tabs">

<view class="tab_title" >

 <block wx:for="{{tabItems}}" wx:key="{{item}}">

  <view bindtap="handleItemActive" data-index="{{index}}">{{item.name}}</view>

 </block>

</view>

<view class="tab_content">

 <slot></slot>

</view>

</view>

// com.js

Component({

properties: {

 tabItems:{

  type:Array,

  value:[]

 }

},

/**

 * 组件的初始数据

 */

data: {

},

/**

 * 组件的方法列表

 */

methods: {

 handleItemActive(e){

  this.triggerEvent('mytap','haha');

 }

}

})

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

myHeader.js

myHeader.js

innerText

innerText

关于小程序前后台的定义和小程序的运行机制,请参考运行机制章节。

黑马程序员-微信小程序基础文档和源码

传智播客-黑马程序员

相关文章: