這篇文章主要介紹“mpvue如何實現微信小程序快遞單號查詢功能”,在日常操作中,相信很多人在mpvue如何實現微信小程序快遞單號查詢功能問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”mpvue如何實現微信小程序快遞單號查詢功能”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
mpvue是什么?
mpvue 是一套定位于開發小程序的前端開發框架,其核心目標是提高開發效率,增強開發體驗。使用該框架,開發者只需初步了解小程序開發規范、熟悉 Vue.js 基本語法即可上手??蚣芴峁┝送暾?Vue.js 開發體驗,開發者編寫 Vue.js 代碼,mpvue 將其解析轉換為小程序并確保其正確運行。此外,框架還通過 vue-cli 工具向開發者提供 quick start 示例代碼,開發者只需執行一條簡單命令,即可獲得可運行的項目。
mpvue簡介點擊查看:http://mpvue.com/
mpvue剛出來的時候確實很火,但目前好像沒有維護,不是很好找官方的文檔,只能通過各大論壇的大佬們總結的文章去研究和論證
使用快遞100的接口 https://m.kuaidi100.com ,mpvue也是完全遵循原生微信小程序的語法,所以接口只允許https.~~~~
**在app.vue主文件里面定義一個 globalData 并初始化一個訂單集合
globalData: {~~~~
orderInfo: []
}**
mine頁面
在此過程中我踩了一個大坑
引入主文件的全局數據需要和vue項目一樣
import {app,globalData} from "../../app.vue"; ~~~~兩個簡單輸入框~~以及綁定了輸入事件~~ mpvue也是完全支持v-model的~~~~
<view class="section"> <input class="order-input" placeholder="請輸入訂單號" @change="bindChange" v-model="value" id="orderId" /> <input class="order-input" placeholder="請輸入快遞公司拼音如shunfeng" @change="bindChange" v-model="value" id="company" /> </view>
查詢按鈕~~~~
<button class="query-btn" size="default" type="primary" loading="" @click="search"> 查詢 </button>
在methods里面寫入相應的方法
methods:{
//上面的方法~~~~
bindChange: function (e) {
console.log(e);
var id;
var value;
id = e.currentTarget.id;
value = e.mp.detail.value + '';
this.inputCon[id] = value;
},
search: function () {
var that = this;
var type = that.inputCon.company;
var postid = that.inputCon.orderId;
var data = {
'type':type,
'postid':postid
}
console.log(this.globalData.queryInfo);
console.log(data);
this.globalData.queryInfo=data;
console.log(app);
wx.request({
url: 'https://m.kuaidi100.com/query',
data: data,
header: {
'content-type': 'application/json'
},
success: (res)=> {
var errTip = res.data.message;
var orderInfo = res.data.data;
console.log(orderInfo);
if(orderInfo.length == 0) {
console.log(errTip)
// that.setData({
// errTip:errTip
// })
this.errTip=errTip
return
}
// that.setData({
// errTip:''
// })
this.errTip=""
this.globalData.orderInfo = orderInfo;
console.log( this.globalData.orderInfo)
wx.navigateTo({
url: '../order/main'
});
wx.setNavigationBarTitle({
title: data.postid
});
}
})
}
}點擊查詢按鈕后跳訂單詳情頁面~~~~
order頁面內容
~~
<template>
<view class="order-list">
<block v-for="(item,index) in orders" :key="index">
<view class="order-time">{{item.ftime}}:</view>
<view class="order-txt">{{item.context}}</view>
</block>
</view>
</template>
<script>
export default {
data(){
return{
orders:[]
}
},
onLoad: function(options) {
拿訂購信息并渲染
console.log(options);
console.log(this.globalData.orderInfo)
var orderInfo = this.globalData.orderInfo;
this.orders=orderInfo
}
};
</script>
<style>
</style>就這樣ok了,當然功能還不是很人性化,因為輸入快遞名稱需要使用拼音,完全依賴于原接口,后面想著如何優化一下
總結
到此,關于“mpvue如何實現微信小程序快遞單號查詢功能”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。