diff --git a/src/main.js b/src/main.js index f028dc3b58c3b1f0d433c2e6b0b1d7bc2b944f44..cce59680c332d67a4a9a8830ebf0747f0b9946c7 100644 --- a/src/main.js +++ b/src/main.js @@ -38,6 +38,7 @@ Vue.directive('highlight', function (el) { Vue.prototype.$cookies = cookies // axios Vue.prototype.$axios = axios +window.$axios_w = axios Vue.prototype.$cookies.set('user_session', 'null') diff --git a/src/plugins/axios.js b/src/plugins/axios.js index d5bc273629619d40ddd025d248b31737408b8fda..430d4690206645d51feaf320a88ba73ce880d623 100644 --- a/src/plugins/axios.js +++ b/src/plugins/axios.js @@ -1,61 +1,61 @@ -'use strict' - -import Vue from 'vue' -import axios from 'axios' - -// Full config: https://github.com/axios/axios#request-config -// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || ''; -// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; -// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; - -let config = { - // baseURL: process.env.baseURL || process.env.apiUrl || "" - // timeout: 60 * 1000, // Timeout - // withCredentials: true, // Check cross-site Access-Control -} - -const _axios = axios.create(config) - -_axios.interceptors.request.use( - function (config) { - // Do something before request is sent - return config - }, - function (error) { - // Do something with request error - return Promise.reject(error) - } -) - -// Add a response interceptor -_axios.interceptors.response.use( - function (response) { - // Do something with response data - return response - }, - function (error) { - // Do something with response error - return Promise.reject(error) - } -) - -Plugin.install = function (Vue, options) { - Vue.axios = _axios - window.axios = _axios - Object.defineProperties(Vue.prototype, { - axios: { - get () { - return _axios - } - }, - $axios: { - get () { - return _axios - } - } - }) -} - -Vue.use(Plugin) - -export default Plugin +// 'use strict' +// +// import Vue from 'vue' +// import axios from 'axios' +// +// // Full config: https://github.com/axios/axios#request-config +// // axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || ''; +// // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; +// // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; +// +// let config = { +// // baseURL: process.env.baseURL || process.env.apiUrl || "" +// // timeout: 60 * 1000, // Timeout +// // withCredentials: true, // Check cross-site Access-Control +// } +// +// const _axios = axios.create(config) +// +// _axios.interceptors.request.use( +// function (config) { +// // Do something before request is sent +// return config +// }, +// function (error) { +// // Do something with request error +// return Promise.reject(error) +// } +// ) +// +// // Add a response interceptor +// _axios.interceptors.response.use( +// function (response) { +// // Do something with response data +// return response +// }, +// function (error) { +// // Do something with response error +// return Promise.reject(error) +// } +// ) +// +// Plugin.install = function (Vue, options) { +// Vue.axios = _axios +// window.axios = _axios +// Object.defineProperties(Vue.prototype, { +// axios: { +// get () { +// return _axios +// } +// }, +// $axios: { +// get () { +// return _axios +// } +// } +// }) +// } +// +// Vue.use(Plugin) +// +// export default Plugin diff --git a/src/service/user.service.js b/src/service/user.service.js index a1a78eabf5e98b5132e3534bf07849a5bd78dd7a..afbad03c0d7db50c2bdae2e8c395f848e70f4246 100644 --- a/src/service/user.service.js +++ b/src/service/user.service.js @@ -1,25 +1,23 @@ -import axios from "axios"; - -export function loginUser(data) { - console.log("用户登录service!", data); - let baseUrl = "/api/user/login/"; - let res = null; - axios +export function loginUser (data) { + console.log('用户登录service!', data) + let baseUrl = '/api/user/login/' + let res = null + window.$axios_w && window.$axios_w .post(baseUrl, data) .then((o) => { - res = o; - console.log("成功认证", res); + res = o + console.log('成功认证', res) // 只返回username localStorage.setItem( - "yma16siteUserInfo", + 'yma16siteUserInfo', JSON.stringify({ username: data.name, //保存一个用户名 password: data.password, }) - ); + ) }) .catch((r) => { - console.log("登录失败!", r); - }); - return res; + console.log('登录失败!', r) + }) + return res }