我通过vue cli 3创建了一个vue项目。为了构造代码,我制作了一个名为common的目录,在其中使用.js ext保存文件。因此,我从Views文件夹中的.vue文件中转移了一些代码,令人惊讶的是它没有用。
我像import Vue from 'vue';
一样导入了Vue并设置了调试器。当我将鼠标悬停在Vue
上时,它表示未定义。我什至导入了我的自定义js文件进行检查,并在那里也出现了同样的问题。
{
"name": "demo-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.5.17",
"vue-axios": "^2.1.3",
"vue-cookie": "^1.1.4",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.0-rc.12",
"@vue/cli-plugin-eslint": "^3.0.0-rc.12",
"@vue/cli-plugin-unit-mocha": "^3.0.0-rc.12",
"@vue/cli-service": "^3.0.0-rc.12",
"@vue/eslint-config-airbnb": "^3.0.0",
"@vue/test-utils": "^1.0.0-beta.20",
"chai": "^4.1.2",
"vue-template-compiler": "^2.5.17"
}
}
import Vue from 'vue';
import { API_URL } from '@/common/config';
import axios from 'axios';
const ApiService = {
init() {
debugger
axios.defaults.baseURL = API_URL;
},
get(resource, slug = '') {
return axios
.get(`${resource}/${slug}`)
.catch((error) => {
throw new Error(`[PTE] ApiService ${error}`);
});
},
post(resource, params) {
debugger
return axios.post(`${resource}`, params);
},
};
export default ApiService;
请注意,我已经导入了Vue,但尚未使用它。解决此问题后,将在以后使用它。