欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)W習(xí)總結(jié)(五)常見問題實(shí)例小結(jié)

 更新時間:2020年06月04日 12:04:52   作者:huangyuxin_  
這篇文章主要介紹了微信小程序常見問題,結(jié)合實(shí)例形式總結(jié)分析了微信小程序常見錯誤、數(shù)據(jù)緩存、界面交換等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例總結(jié)了微信小程序常見問題。分享給大家供大家參考,具體如下:

問題一

先來看我遇到的第一個問題
以下是我創(chuàng)建的目錄

當(dāng)創(chuàng)建完這個json文件之后,報了下面一個錯

這個是我的報錯信息。

解決方法:打開這個json文件,輸入兩個一對花括號完事。

問題二

以下是我引入js的代碼,絕對路徑報錯。

var postsData = require('/data/post-data.js')

報錯信息:

Uncaught Error: module “pages/post/data/post-data.js” is not defined

改正后的

var postsData = require('../../data/post-data.js')

數(shù)據(jù)

如果在onLoad方法中,如果是異步執(zhí)行一個數(shù)據(jù)綁定,則需要使用this.setData方法。如果不是異步是同步的話,那么只需要對this.data賦值可實(shí)現(xiàn)數(shù)據(jù)綁定

格式化代碼

shift + alt + F

數(shù)據(jù)緩存

需要說明的這個是數(shù)據(jù)的本地緩存,可以對本地緩存進(jìn)行設(shè)置、獲取和清理。同一個微信用戶,同一個小程序 storage 上限為 10MB。

設(shè)置緩存

wx.setStorageSync('key','value');

獲取緩存

wx.getStorageSync('key')

清除緩存

//清除所有緩存
wx.clearStorageSync();
//清除指定緩存
wx.clearStorageSync('key');

界面交互

顯示消息提示框

wx.showToast({
 title: '成功',
 icon: 'success',
 duration: 2000 //設(shè)置彈框時間
})
//也可以這么寫  三元運(yùn)算的方式 根據(jù)需要來
wx.showToast({
 title:result?'確定收藏':'取消收藏',
 duration: 2000 
})

顯示loading

    wx.showLoading({
     title: '加載中',  //顯示加載
    })

    setTimeout(function () {
     wx.hideLoading()  //取消加載
    }, 2000)

詢問框

    wx.showModal({
     title: 'hello',
     content: postCollected?'確認(rèn)收藏嗎':'確認(rèn)取消收藏嗎',
     success: function (res) {
      if (res.confirm) {
       //更新緩存
       wx.setStorageSync('post_collected', postsCollected);
       that.setData({
        collected: postCollected
       })
      } else if (res.cancel) {
       console.log('用戶點(diǎn)擊取消')
      }
     }
    })

打印的res

​顯示操作菜單

   onShareTap:function(event){
    wx.showActionSheet({
     itemList: [
      '分享給微信好友',
      '分享到朋友圈',
      '分享到QQ'
     ],
     itemColor:'#405f80',
     success:function(res){
      console.log(res)
     }
    })
   }

顯示效果

獲取全局變量

app.js

app({
  globalData: {
  g_name: "huangyuxin"
 }
})

使用

detail.js

var app = getApp();

希望本文所述對大家微信小程序設(shè)計有所幫助。

相關(guān)文章

最新評論