zoukankan      html  css  js  c++  java
  • vue---import的几种表现形式

    在使用vue开发项目的时候,很多使用会import很多模块,或者组件,下面说下import的几种表现形式:

    例如:我在 src / api / table.js

    import request from '@/utils/request'
    
    export function getList(params) {
      return request({
        url: '/table/list',
        method: 'get',
        params
      })
    }
    
    export function getLists(params) {
      return request({
        url: '/table/list',
        method: 'get',
        params
      })
    }

    我需要使用里面的方法,有几种方法:

    第一种:引入当个方法

    import {getList} from '@/api/table';

    具体的使用:

    import {getList} from '@/api/table';
    export default {
      data() {
        return {
            list: null,
            listLoading: true
        }    
      },
      created(){
        this.fetchData();
      },
      methods: {
        fetchData() {
          console.log(getList);
          getList().then(response =>{
            console.log('b');
          });
        }
      }
    }

    第二种:引入多个方法

    import {getList,getLists} from '@/api/table';
    export default {
      data() {
        return {
            list: null,
            listLoading: true
        }    
      },
      created(){
        this.fetchData();
      },
      methods: {
        fetchData() {
          console.log(getList);
          getList().then(response =>{
            console.log('b');
          });
          console.log(getLists);
        }
      }
    }
  • 相关阅读:
    第10组 Beta冲刺 (4/5)
    第10组 Beta冲刺 (3/5)
    第10组 Beta冲刺 (2/5)
    第10组 beta冲刺(1/5)
    软工实践个人总结
    第01组 每周小结(3/3))
    第01组 每周小结(2/3)
    第01组 每周小结 (1/3)
    第01组 beta冲刺总结
    第01组 beta冲刺(5/5)
  • 原文地址:https://www.cnblogs.com/e0yu/p/10775757.html
Copyright © 2011-2022 走看看