From 630f2231abe96eb9e28809ee48b0ee8f3e1ce64c Mon Sep 17 00:00:00 2001 From: liushuyu Date: Mon, 21 Oct 2019 15:58:30 -0600 Subject: [PATCH] ui: use axios as possible --- ui/.eslintrc.js | 3 ++- ui/package.json | 1 + ui/src/main.js | 9 +++++---- ui/src/views/DownloadConfig.vue | 16 ++++++++-------- ui/yarn.lock | 5 +++++ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ui/.eslintrc.js b/ui/.eslintrc.js index 6b2e11f..6363fc2 100644 --- a/ui/.eslintrc.js +++ b/ui/.eslintrc.js @@ -10,7 +10,8 @@ module.exports = { rules: { 'no-console': 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', - 'no-redeclare': 'off' + 'no-redeclare': 'off', + 'camelcase': 'off' }, parserOptions: { parser: 'babel-eslint' diff --git a/ui/package.json b/ui/package.json index 1d2f4dc..baea5b3 100644 --- a/ui/package.json +++ b/ui/package.json @@ -11,6 +11,7 @@ "axios": "^0.19.0", "buefy": "^0.8.5", "vue": "^2.6.10", + "vue-axios": "^2.1.5", "vue-router": "^3.1.3" }, "devDependencies": { diff --git a/ui/src/main.js b/ui/src/main.js index badbf0c..d0b938f 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -2,12 +2,14 @@ import Vue from 'vue' import App from './App.vue' import router from './router' import axios from 'axios' -import { ajax, stream_ajax as streamAjax } from './helpers' +import VueAxios from 'vue-axios' +import { stream_ajax as streamAjax } from './helpers' import Buefy from 'buefy' import 'buefy/dist/buefy.css' Vue.config.productionTip = false Vue.use(Buefy) +Vue.use(VueAxios, axios) // Borrowed from http://tobyho.com/2012/07/27/taking-over-console-log/ function intercept (method) { @@ -64,8 +66,8 @@ function disableShortcuts (e) { } // Check to see if we need to enable dark mode -ajax('/api/dark-mode', function (enable) { - if (enable) { +axios.get('/api/dark-mode').then(function (resp) { + if (resp.data === true) { document.body.classList.add('has-background-black-ter') } }) @@ -120,7 +122,6 @@ var app = new Vue({ } }) }) }, - ajax: ajax, stream_ajax: streamAjax } }).$mount('#app') diff --git a/ui/src/views/DownloadConfig.vue b/ui/src/views/DownloadConfig.vue index 38b6567..6e2d5b5 100644 --- a/ui/src/views/DownloadConfig.vue +++ b/ui/src/views/DownloadConfig.vue @@ -18,19 +18,19 @@ export default { methods: { download_install_status: function () { var that = this - this.$root.ajax('/api/installation-status', function (e) { - that.$root.metadata = e + this.$http.get('/api/installation-status').then(function (resp) { + that.$root.metadata = resp.data that.download_config() }) }, download_config: function () { var that = this - this.$root.ajax('/api/config', function (e) { - that.$root.config = e + this.$http.get('/api/config').then(function (resp) { + that.$root.config = resp.data that.choose_next_state() - }, function (e) { + }).catch(function (e) { console.error('Got error while downloading config: ' + e) @@ -83,9 +83,9 @@ export default { // Need to do a bit more digging to get at the // install location. - this.$root.ajax('/api/default-path', function (e) { - if (e.path != null) { - app.install_location = e.path + this.$http.get('/api/default-path').then(function (resp) { + if (resp.data.path != null) { + app.install_location = resp.data.path } }) diff --git a/ui/yarn.lock b/ui/yarn.lock index 207190f..d2114d3 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -8094,6 +8094,11 @@ vm-browserify@^1.0.1: resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019" integrity sha512-iq+S7vZJE60yejDYM0ek6zg308+UZsdtPExWP9VZoCFCz1zkJoXFnAX7aZfd/ZwrkidzdUZL0C/ryW+JwAiIGw== +vue-axios@^2.1.5: + version "2.1.5" + resolved "https://registry.yarnpkg.com/vue-axios/-/vue-axios-2.1.5.tgz#1af4bf1218ed71309c76afb38d0f683e312c24a7" + integrity sha512-th5xVbInVoyIoe+qY+9GCflEVezxAvztD4xpFF39SRQYqpoKD2qkmX8yv08jJG9a2SgNOCjirjJGSwg/wTrbmA== + vue-eslint-parser@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-5.0.0.tgz#00f4e4da94ec974b821a26ff0ed0f7a78402b8a1"