这篇文章主要介绍“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如何实现微信小程序快递单号查询功能”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!