最近用uniapp 做了一个手机端项目,作为一个没有接触过uniapp的程小白,客户催得紧,慌得一
template中
<view class="account-setting-input xst-flex">
<text>{{i18n.AccountToBeCredited}}</text> // 这是 i18n 多语言
<input :placeholder="$t(i18n.PleaseFillInYourSalletAddress)" v-model="address" /> //这里是转账地址
<image src="..." @click="orcode"></image> // 图片是扫码的那个图片 添加一个点击事件
</view>
<view class="account-setting-input xst-flex">
<text>{{i18n.EachOthersNickname}}</text>
<input :placeholder="$t(i18n.EachOthersNickname)" v-model="username" /> // 这是填写要转账的人的昵称
</view> // data 里要定义v-model 的两个变量
js中
onLoad(option) {
// #ifdef APP-PLUS
if (typeof(option.address) != 'undefined') {
this.address = option.address.replace(/\"/g, "");
var addres = option.address.replace(/\"/g, "");
} else {
this.address = '';
}
// #endif
}
methods 中
// 扫码转账 点击事件的方法
orcode: function() {
var that = this;
uni.scanCode({
success: function(res) {
// 这是自己封装的uniapp 的Ajax请求 main.js 中配置 这里调用
var data = {
address: res.result
}
that.address = res.result;
// 要传token 所以是promis 不传token 是promislo 把token 和 language 放在header 里了,这里就不用写了
that.proims(data, '接口地址').then((res) => {
console.log(res);
if (res.data.code == 1) {
that.username = res.data.data;
} else {
uni.showToast({
title: res.data.message,
icon: 'none'
})
}
}, (res) => {
uni.showToast({
title: res.data.message,
icon: 'none'
})
})
}
});
}