全局注册axios

main
zggsong 2 years ago
parent 4936574df4
commit 0f7e8a4b10

BIN
.DS_Store vendored

Binary file not shown.

@ -18,20 +18,20 @@
</template>
<script setup>
import { ref, reactive } from "vue"
import { ref, reactive, getCurrentInstance } from "vue"
import { useRouter, useRoute } from "vue-router"
import { ElMessage } from 'element-plus'
import axios from 'axios'
axios.defaults.baseURL = '/api'
const router = useRouter();
const route = useRoute(); //
let user = reactive({ tel: "", pwd: "" });
// axios
const {appContext} = getCurrentInstance();
function login() {
async function login() {
//
axios.post('/auth/login', null,
await appContext.config.globalProperties.$http.post('/auth/login', null,
{
params: {
telephone: user.tel,

@ -21,20 +21,19 @@
</template>
<script setup>
import { ref, reactive } from 'vue'
import { ref, reactive, getCurrentInstance } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import axios from 'axios'
axios.defaults.baseURL = '/api'
const router = useRouter()
const route = useRoute()//
const {appContext} = getCurrentInstance()
let user = reactive({ name: '', tel: '', pwd: '' })
function register() {
axios.post('/auth/register', null,
async function register() {
await appContext.config.globalProperties.$http.post('/auth/register', null,
{
params: {
name: user.name,

@ -3,8 +3,9 @@ import { createApp } from "vue";
import App from "./App.vue";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import { createRouter, createWebHistory } from "vue-router";
import axios from "axios";
axios.defaults.baseURL = '/api'
const routes = [
{ path: "/login", component: () => import("./components/login/Index.vue") },
@ -19,9 +20,9 @@ const router = createRouter({
history: createWebHistory(),
routes,
});
//https://cn.vuejs.org/api/application.html#app-config-compileroptions
let app = createApp(App);
app.use(router);
app.use(ElementPlus);
app.config.globalProperties.$http = axios;
app.mount("#app");

Loading…
Cancel
Save