mpvue剛出來的時候確實很火,但目前好像沒有維護,不是很好找官方的文檔,只能經過各大論壇的大佬們總結的文章去研究和論證
使用快遞100的接口https://m.kuaidi100.com,mpvue也是徹底遵循原生微信小程序的語法,因此接口只容許https.~~~~
**在app.vue主文件裏面定義一個globalData
並初始化一個訂單集合vue
globalData: {~~~~ orderInfo: [] }
在此過程當中我踩了一個大坑
引入主文件的全局數據須要和vue項目同樣import {app,globalData} from "../../app.vue";
json
兩個簡單輸入框~~以及綁定了輸入事件~~ 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 }); } }) } }
點擊查詢按鈕後跳訂單詳情頁面微信小程序
<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了,固然功能還不是很人性化,由於輸入快遞名稱須要使用拼音,徹底依賴於原接口,後面想着如何優化一下微信