免费国产欧美国日产_少妇AV一区二区三区无码_蜜桃精品av无码喷奶水小说_jk18禁网站视频_精产国品一二三级产品区别_被夫の上司に犯波多野结衣_78m成人手机免费看_最爽最刺激18禁视频_偷偷色噜狠狠狠狠的777米奇

易優(yōu)GEO 重磅上線 ~ 一站式GEO優(yōu)化工具,讓豆包、文心一言、DeepSeek 在回答中主動推薦你的品牌,搶占AI流量入口!  點擊查看

小程序模板網(wǎng)

小程序公用js提取到app.js中調(diào)用的實例

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

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">跳轉(zhuǎn)到測試頁面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:"測試數(shù)據(jù)1"
  5. },
  6. /*調(diào)用公共方法test01*/
  7. test01:function(event){
  8. var that=this;
  9. app.test01(event,that);
  10. },
  11. /*調(diào)用公共方法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: "測試數(shù)據(jù)1"
  5. },
  6. /*調(diào)用公共方法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數(shù)據(jù)";
  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. })


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.szcjxy.com/wxmini/doc/course/23963.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢: 點擊咨詢
在線客服