<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody" class="grace-body">
<view class="grace-title grace-margin-top">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">PK组件演示</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-margin-top">
<gracePK :title="title" :status="PKStatus" :progress="PKProgress" @choose="choose"></gracePK>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import gracePK from "../../graceUI/components/gracePK.vue";
export default {
data() {
return {
title : ['赞同', '反对'],
PKProgress : [70,30,'7000 票', '3000 票'],
PKStatus : 'button'
}
},
methods:{
choose : function(e){
// 获取用户提交的是左边还是右边
console.log(e);
// 等到投票数据后连接后端 api 完成投票
// 然后改变组件状态 展示投票结果
// 模拟一个api请求
uni.showLoading({ mask:true, title:"提交中" });
setTimeout(()=>{
// 设置进度 进度值应该来自 api
this.PKProgress = [75,25,'7500 票', '2500 票'];
// 改变组件状态
this.PKStatus = 'progress';
uni.hideLoading();
}, 1000);
}
},
components:{
gracePage,gracePK
}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody" class="grace-body">
<view class="grace-title grace-margin-top">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">PK组件演示</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-margin-top">
<gracePK :title="title" :status="PKStatus" :progress="PKProgress" @choose="choose"></gracePK>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import gracePK from "../../graceUI/weexComponents/gracePK.nvue";
export default {
data() {
return {
title : ['赞同', '反对'],
PKProgress : [70,30,'7000 票', '3000 票'],
PKStatus : 'button'
}
},
methods:{
choose : function(e){
// 获取用户提交的是左边还是右边
console.log(e);
// 等到投票数据后连接后端 api 完成投票
// 然后改变组件状态 展示投票结果
// 模拟一个api请求
uni.showLoading({ mask:true, title:"提交中" });
setTimeout(()=>{
// 设置进度 进度值应该来自 api
this.PKProgress = [75,25,'7500 票', '2500 票'];
// 改变组件状态
this.PKStatus = 'progress';
uni.hideLoading();
}, 1000);
}
},
components:{
gracePage,gracePK
}
}
</script>
<style>
</style>
.wxml
<gracePage customHeader="{{false}}">
<!-- 页面主体 -->
<view slot="gBody" class="grace-body">
<view class="grace-title grace-margin-top">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">PK组件演示</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-margin-top">
<gracePK title="{{title}}" status="{{PKStatus}}" progress="{{PKProgress}}" bind:choose="choose"></gracePK>
</view>
</view>
</gracePage>.js
Page({
data:{
title : ['赞同', '反对'],
PKProgress : [70,30,'7000 票', '3000 票'],
PKStatus : 'button'
},
choose : function(e){
// 获取用户提交的是左边还是右边
console.log(e);
// 等到投票数据后连接后端 api 完成投票
// 然后改变组件状态 展示投票结果
// 模拟一个api请求
wx.showLoading({ mask:true, title:"提交中" });
setTimeout(()=>{
// 设置进度 进度值应该来自 api
this.setData({'PKProgress' : [75,25,'7500 票', '2500 票'], 'PKStatus':'progress'});
wx.hideLoading();
}, 1000);
}
}).json
{
"usingComponents": {
"gracePage" : "../../graceUI/components/gracePage",
"gracePK": "../../graceUI/components/gracePK"
}
}