微信小程序开发快速入手

1.在page中的修改数据的setData函数,需要传递的是一个对象。

 that.setData({

 src: res.tempFilePath

 })

2.在 onload 事件中,可以获取wx.navigateTo传递过来的参数

主页面

 url = '../detail/detail?id=' + id;

 wx.navigateTo({

     url: url

    })

子页面

 ​onLoad:function(options){

    // 页面初始化 options为页面跳转所带来的参数

    this.fetchData(options);

   }

页面跳转上面是通过api实现的,还有一种是通过指令来实现的

<navigator url="navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator> 

<navigator url="redirect?title=redirect" redirect hover-class="other-navigator-hover">在当前页打开</navigator>

3.引入模块需要如下

 var Api = require('../../utils/api.js') 携带文件后缀.js

4.目前和后端的数据接口,主要是JSON数据,不支持直接用html片段,构造视图。

5.每增加一个页面,都需要在app.json的pages数组进行配置,否则无法路由无法找到该页面

6.页面布局可以优选 flex布局,非常适合。

7.快速搭建小应用的脚手架

安装

// 安装我们的命令 

//mac sudo npm i -g wxapp

 // window npm i -g wxapp

使用

// 初始化一个目录结构

 wxapp init [project_name] 

// 如 wxapp init first-wxapp

DEV

npm run dev // 默认启用了ES6模式

npm run dev-es5 // 不启用ES6模式

接着我们只需要打开微信开发者工具,添加项目,那个项目目录指向为dist目录即可。

原文地址:https://www.cnblogs.com/10manongit/p/12735774.html