网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

小程序公用js提取到app.js中調用的實例

發布時間:2018-04-25 09:13 所屬欄目:小程序開發教程

index.wxml:

 

				
  1. <view class="datas" bindtap="test01" data-id="0">
  2. <text>{{page}}</text>
  3. </view>
  4.  
  5. <view class="datas" bindtap="test02" data-id="1">
  6. <text>測試2</text>
  7. </view>
  8.  
  9. <navigator class="test2" url="/pages/page2/page2">跳轉到測試頁面page2</navigator>

index.wxss:

 

				
  1. .datas{
  2. width: 200px;
  3. height: 100px;
  4. background-color: #188eee;
  5. text-align: center;
  6. line-height: 100px;
  7. color: #fff;
  8. margin-top: 20px;
  9. }
  10. .test2{
  11. width: 200px;
  12. height: 50px;
  13. line-height: 50px;
  14. text-align: center;
  15. color: #fff;
  16. background-color: red;
  17. margin-top: 50px;
  18. }

index.js

 

				
  1. var app=getApp();
  2. Page({
  3. data: {
  4. page:"測試數據1"
  5. },
  6. /*調用公共方法test01*/
  7. test01:function(event){
  8. var that=this;
  9. app.test01(event,that);
  10. },
  11. /*調用公共方法test02*/
  12. test02: function () {
  13. app.test02();
  14. }
  15. })

page2.wxml:

 

				
  1. <view class="page2" bindtap="test01" data-id="page2">
  2. {{page}}
  3. </view>

page2.wxss

 

				
  1. .page2{
  2. width: 200px;
  3. height: 100px;
  4. background-color: #188eee;
  5. text-align: center;
  6. line-height: 100px;
  7. color: #fff;
  8. margin-top: 20px;
  9. }

page2.js

 

				
  1. var app=getApp();
  2. Page({
  3. data: {
  4. page: "測試數據1"
  5. },
  6. /*調用公共方法test01*/
  7. test01: function (event) {
  8. var that = this;
  9. app.test01(event, that);
  10. },
  11. })

app.json

 

				
  1. {
  2. "pages":[
  3. "pages/index/index",
  4. "pages/page2/page2"
  5. ],
  6. "window":{
  7. "backgroundTextStyle":"light",
  8. "navigationBarBackgroundColor": "#fff",
  9. "navigationBarTitleText": "WeChat",
  10. "navigationBarTextStyle":"black"
  11. }
  12. }

app.js

 

				
  1. App({
  2.  
  3. test01: function (event, that){
  4. that.data.page= "修改后的page數據";
  5. that.setData({
  6. page: that.data.page
  7. });
  8. console.log(event.currentTarget.dataset.id);
  9. },
  10.  
  11. test02:function(){
  12. console.log("test2");
  13. }
  14. })


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23963.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×