在使用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); } } }