用户工具

站点工具


mina:page_function

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
mina:page_function [2020/08/24 15:11] – [4. 使用 behaviors] sabertoymina:page_function [2020/08/24 15:36] (当前版本) – [5. 使用 Component] sabertoy
行 129: 行 129:
 ===== -#4 使用 behaviors() ===== ===== -#4 使用 behaviors() =====
  
-behaviors 可以用来让多个页面有<wrap em>相同的数据字段和方法</wrap>+[[https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html | behaviors]] 可以用来让多个页面有<wrap em>相同的数据字段和方法</wrap>。 [[https://developers.weixin.qq.com/miniprogram/dev/reference/api/Behavior.html|参数说明]]
  
 <code javascript> <code javascript>
行 149: 行 149:
 var myBehavior = require('./my-behavior.js') var myBehavior = require('./my-behavior.js')
 Page({ Page({
-  behaviors: [myBehavior],+  behaviors: [myBehavior], //引入其它的 behavior
   onLoad: function() {   onLoad: function() {
     this.data.sharedText === 'This is a piece of data shared between pages.'     this.data.sharedText === 'This is a piece of data shared between pages.'
行 155: 行 155:
 }) })
 </code>  </code> 
 +
 +
 +
 +==== - 组件中使用 ====
 +
 +
 +
  
  
行 162: 行 169:
 ===== -#5 使用 Component ===== ===== -#5 使用 Component =====
  
 +Page 构造器适用于简单的页面。但对于复杂的页面, Page 构造器可能并不好用。
 +
 +[[https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/component.html | Component]] 构造器的主要区别是:<wrap em>方法需要放在 methods: { } 里面</wrap>
 +
 +<code javascript>
 +Component({
 +  data: {
 +    text: "This is page data."
 +  },
 +  methods: {
 +    onLoad: function(options) {
 +      // 页面创建时执行
 +    },
 +    onPullDownRefresh: function() {
 +      // 下拉刷新时执行
 +    },
 +    // 事件响应函数
 +    viewTap: function() {
 +      // ...
 +    }
 +  }
 +})
 +<code>
  
mina/page_function.1598253105.txt.gz · 最后更改: 2020/08/24 15:11 (外部编辑)