亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

mpvue網(wǎng)易云短信接口實(shí)現(xiàn)小程序短信登錄的示例代碼

 更新時(shí)間:2020年04月03日 11:32:26   作者:Banshee  
這篇文章主要介紹了mpvue網(wǎng)易云短信接口實(shí)現(xiàn)小程序短信登錄的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

上一篇簡(jiǎn)單介紹了mpvue實(shí)現(xiàn)快遞單號(hào)查詢,慢慢發(fā)現(xiàn)mpvue真的和vue很像,但它有幾乎十分的吻合小程序的語(yǔ)法規(guī)范,剛開(kāi)始用起來(lái)會(huì)覺(jué)得特點(diǎn)的爽,但涉及到細(xì)節(jié)卻是有很多采坑的地方.今天利用網(wǎng)上的網(wǎng)易云接口,再結(jié)合mpvue簡(jiǎn)單寫一寫小程序短信驗(yàn)證登錄.

簡(jiǎn)單封裝的一個(gè)網(wǎng)絡(luò)請(qǐng)求文件,網(wǎng)易云接口網(wǎng)上大佬們GitHub上還是比較的多而且開(kāi)源

const baseURL = "https://*****:1717"; //基路徑

exports.http = function({url,method,data,headers,success}){

  mpvue.showLoading({
    title: '加載中...',
  })
  mpvue.request({
  //請(qǐng)求鏈接
  url:baseURL+url,
  //請(qǐng)求方式
  method:method,
  //參數(shù)
  data:data,
  //請(qǐng)求頭
  header:headers,
  success:res=>{
    console.log(res.data);
    success(res);
    //加載框~~~~
    mpvue.hideLoading();
    mpvue.showToast({
      title:res.data.msg
    })
  }
  })
}

home頁(yè)面:

小程序的模態(tài)框

<view>

<modal
 v-if="loginData.show"
 title="登錄"
 confirmText="立即登錄"
 cancelText="取消登錄"
 @confirm="gotoLogin"
 @cancel="cancelLogin"
 cancelColor="#CC0033"
 confirmColor="#CCFF66"
>
 <label class="h-label">
  <input type="tel" placeholder="請(qǐng)輸入手機(jī)號(hào)" v-model="loginData.mobile" @click="getMoblie" />
 </label>
 <label class="h-label">
  <input type="number" placeholder="請(qǐng)輸入驗(yàn)證碼" v-model="loginData.code" @click="getCode" />
 </label>
 <button
  type="primary"
  size="defaultSize"
  loading="loading"
  @click="sendCode"
  hover-class="defaultTap"
 >發(fā)送驗(yàn)證碼</button>
</modal>
</view>

基本邏輯是頁(yè)面加載進(jìn)來(lái),先判斷是否有登錄,因?yàn)橛械卿浀奈視?huì)存儲(chǔ)于Storage里面,若沒(méi)有登錄就彈出模態(tài)框并登錄后將用戶信息存儲(chǔ)于Storage里面

//給默認(rèn)值
 data() {
  return {
   loginData: {
    show: true,
    mobile: 1383838438,
    code: ""
   }
 },

mounted里面判斷一下是否有登錄狀態(tài)

mounted() {
  this.loginData.show = !wx.getStorageSync("isLogin");
  }

methods里面寫入登錄和取消登錄事件:

methods: {
//去登錄

gotoLogin() {
 //效驗(yàn)驗(yàn)證碼
 http({
  url: "/captcha/verify",
  method: "GET",
  data: {
   phone: this.loginData.mobile,
   captcha: this.loginData.code
  },
  success: res => {
   if (res.data.code == 200) {
    //將token和手機(jī)號(hào)以存入前端緩存
    wx.setStorageSync("isLogin", true);
    wx.setStorageSync("moblie", this.loginData.mobile);
   }
     //讓彈框消失
     this.loginData.show = false;
    }
   });
  },
  
 //取消登錄
  cancelLogin() {
   console.log("888");
   (this.loginData.show = false),
    wx.showToast({
     title: "游客訪問(wèn)"
    });
  },
 
//獲取手機(jī)號(hào)
  getMoblie() {
   console.log("000");
   console.log(this.loginData.mobile);
   this.loginData.mobile;
  },
  //獲取驗(yàn)證碼
  getCode() {
   this.loginData.code;
  },
//發(fā)送驗(yàn)證碼

sendCode() {
 http({
  url: "/captcha/sent",
  method: "GET",
  data: {
   phone: this.loginData.mobile
  },
  success: res => {
   console.log(res.data);
   wx.hideLoading();
   wx.showToast({
    title: res.data.code
   });
  }
 });
}
}

然后就OK了

到此這篇關(guān)于mpvue網(wǎng)易云短信接口實(shí)現(xiàn)小程序短信登錄的示例代碼的文章就介紹到這了,更多相關(guān)mpvue 小程序短信登錄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論