main.js 文件
JavaScript代码
- /*** sleep ***/
 - Vue.prototype.$sleep = time => {
 - return new Promise((resolve, reject) => {
 - window.setTimeout(() => {
 - resolve(true)
 - }, time)
 - })
 - }
 
增加测试页面
XML/HTML代码
- <!--
 - * @Description: npage.vue
 - * @Version: 1.0
 - * @Author: Jesse Liu
 - * @Date: 2022-08-01 20:32:06
 - * @LastEditors: Jesse Liu
 - * @LastEditTime: 2023-09-07 13:24:11
 - -->
 - <template>
 - <div class="wscn-http404-container">
 - <h2 style="font-weight: normal; line-height: 160%;">userInfo ========= {{ userInfo }}</h2>
 - <h2 style="font-weight: normal; line-height: 160%;">configInformation ========= {{ configInformation }}</h2>
 - <h1 style="line-height:300px; text-align:center">npage.vue (新测试文件)</h1>
 - <div>time:</div>
 - </div>
 - </template>
 - <script>
 - import { mapState } from "vuex";
 - import { parseTime } from '@/utils'
 - import { downloadFile } from "@/utils/getFile";
 - export default {
 - name: 'PageTest',
 - computed: {
 - ...mapState("user", ["userInfo","configInformation"]),
 - message() {
 - return 'PageTest'
 - },
 - parseTime: parseTime
 - },
 - mounted() {
 - this.$store.dispatch("case/casesList/downloadFile",{}).then((res)=>{
 - // let data = res.data;
 - // let headers = res.headers;
 - // /*** 调用下载文件 ***/
 - // downloadFile(data, headers)
 - })
 - /*** 多定时器同时调用 ***/
 - this.getStateA();
 - this.getStateB();
 - /*** 业务请求接口调用示例 ***/
 - this.casePage();
 - },
 - methods: {
 - /*** 定时器演示方法 ***/
 - async getStateA(){
 - /*** 定时器只管计算时间钩子标记 ***/
 - console.log('sleepStateA ~~~ 开始')
 - /*** 多定时处理任务A ***/
 - console.time('sleepStateA');
 - let sleepStateA = await this.$sleep(5000);
 - console.log('sleepStateA ~~~ 结束', sleepStateA)
 - console.timeEnd('sleepStateA');
 - return sleepStateA;
 - },
 - /*** 定时器演示方法 ***/
 - async getStateB(){
 - /*** 定时器只管计算时间钩子标记 ***/
 - console.log('sleepStateB ~~~ 开始')
 - /*** 多定时处理任务B ***/
 - console.time('sleepStateB');
 - let sleepStateB = await this.$sleep(10000);
 - console.log('sleepStateB ~~~ 结束', sleepStateB)
 - console.timeEnd('sleepStateB');
 - return sleepStateB;
 - },
 - /*** 模拟示例业务的状态 ***/
 - async getCaseState(){
 - /*** 定时器只管计算时间钩子标记 ***/
 - let sleepStateCase = await this.$sleep(10000);
 - return sleepStateCase;
 - },
 - /*** 模拟示例业务主方法 ***/
 - async casePage(state = true, n = 0){
 - /*** 定义及获取数据状态 ***/
 - let runling = true;
 - let getCaseState = await this.getCaseState();
 - /*** 业务逻辑处理及使用 ***/
 - if(state && getCaseState) {
 - /*** 请求接口拿状态和后端约定状态码(根据状态码去更改runling的布尔值) ***/
 - // 写你的vuex调用方法,如:this.$store.dispatch('user/record', {})
 - /*** 以下代码是为了演示模拟3次请求后,状态变更,供参考 ***/
 - /*** 假设后端接口告诉你可以终止执行调用的状态 (比如后端调用3次后就更改了状态) ***/
 - let index = n;
 - index +=1;
 - console.log('第['+ index + ']次调用后端接口~~');
 - if(index >= 3) {
 - runling = false;
 - }
 - this.casePage(runling, index);
 - }
 - else{
 - console.log('===========================================\n定时器已经结束关停,累计调用共: ' + n + '次~~');
 - }
 - }
 - }
 - }
 - </script>
 - <style lang="scss" scoped>
 - </style>
 



 2023/09/07 13:29 | by 
  
 
 
 
 
 


