zoukankan      html  css  js  c++  java
  • vue await async

    1. await, async使用
    函数头单独封装出去
    views/methods.js页面
    import { one } from 'api/general.js';
    async function change() {
    let data = {},
    Obj = {},
    key = '';

    data = await one();

    for (key in data.data) {
    Obj[key] = data.data[key];
    }
    return Obj;
    }

    export {
    change
    }


    ------------------------------
    api/general.js页面
    //先执行的函数
    function one() {
    return fetch({
    url: url,
    method: 'get',
    })
    }

    export {
    one
    }


    //传参的:
    //function one(data) {
       // return fetch({
    // url: url,
    // method: 'get',
    // data: 'data'
    // })
    //}


    ------------------------
    页面调用封装的函数头
    import { change } from 'views/methods.js'

    export default { 
         data() {
    changeObj : {}
    }
         created() {
    change().then(res => {
    this.changeObj = res;
    });
        }
  • 相关阅读:
    Spring Cloud
    Hibernate 缓存
    Spring 快速入门
    Junit 单元测试
    Spring Cloud 笔记
    Swagger SpringBoot 集成
    Apache Shiro 权限框架
    Spring Boot
    跨域问题
    BeX5 常见问题解决办法
  • 原文地址:https://www.cnblogs.com/namehou/p/11730694.html
Copyright © 2011-2022 走看看