| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <template>
- <div @click="tologin">登录</div>
- <h2> {{ store.name }}</h2>
- <h1 @click="changeName">修改名称</h1>
- <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" />
- <div @click="networkRequest()">点击发起网络请求</div>
- </template>
- <script lang="ts" setup>
- import { useRoute, useRouter } from 'vue-router'
- import { useStore } from "../store/index";
- import { post } from '@/utils/request'
- const router = useRouter()
- const store = useStore()
- function tologin() {
- router.push({
- name: 'index'
- })
- }
- function changeName(): void {
- store.name = '索索'
- }
- async function networkRequest(): Promise<void> {
- console.log('发起请求')
- const requestUrl = '/user/loginAdmin'
- const data = {
- username: '18130408100',
- password: '220926'
- }
- // proxy.$post(requestUrl, data)
- // .then((response: any) => {
- // console.log(response, '<=== 请求返回的数据')
- // })
- const res = await post(requestUrl, data)
- console.log(res, '<=== 请求返回的数据')
- }
- interface Tree {
- label: string
- children?: Tree[]
- }
- const handleNodeClick = (data: Tree) => {
- console.log(data)
- }
- const data: Tree[] = [
- {
- label: 'Level one 1',
- children: [
- {
- label: 'Level two 1-1',
- children: [
- {
- label: 'Level three 1-1-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 2',
- children: [
- {
- label: 'Level two 2-1',
- children: [
- {
- label: 'Level three 2-1-1',
- },
- ],
- },
- {
- label: 'Level two 2-2',
- children: [
- {
- label: 'Level three 2-2-1',
- },
- ],
- },
- ],
- },
- {
- label: 'Level one 3',
- children: [
- {
- label: 'Level two 3-1',
- children: [
- {
- label: 'Level three 3-1-1',
- },
- ],
- },
- {
- label: 'Level two 3-2',
- children: [
- {
- label: 'Level three 3-2-1',
- },
- ],
- },
- ],
- },
- ]
- const defaultProps = {
- children: 'children',
- label: 'label',
- }
- </script>
|