客户管理v-show -> v-if
This commit is contained in:
parent
20a88c45b8
commit
0d4dbfd0ce
2
App.vue
2
App.vue
|
|
@ -8,7 +8,7 @@
|
|||
// 如果还没有 token,则设置一个测试 token
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
const testToken = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjA4ZmEzNGU0LTU3NWYtNDdmMy1iY2IyLTBhMDVhNWVhOWRmNiJ9.bjaWTzwNZWyUD1UEX0te4u0a9vPhS5iLxxubgvpVF6rQ_ZhGfkvS8rdwr_kLNEWAILgLJQW3h8whDHMq9NzLtA'
|
||||
const testToken = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjJiNWZkNDAyLTFiYWQtNDI5YS04ZDFkLTllZGE0Y2VkOWIxMyJ9.2UEvAG6OtJ0WZoJxjPjGzGhdgxAclzEqqPl_K94kbcCVs9YplENwZe2AcdsLkdLsc7EnDbRif-xuhWlTKF78WQ'
|
||||
uni.setStorageSync('token', testToken)
|
||||
console.log('已设置测试 token:', testToken)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<!-- 内容区域 -->
|
||||
<view class="content-wrapper">
|
||||
<!-- 客户管理(底部导航栏选中时显示,使用 v-show 避免组件销毁重建) -->
|
||||
<CustomerManagement v-show="value === 3" />
|
||||
<CustomerManagement v-if="value === 3" />
|
||||
|
||||
<!-- 其他内容(底部导航栏未选中客户管理时显示) -->
|
||||
<template v-else>
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
/**
|
||||
* Pinia Store 使用示例
|
||||
*
|
||||
* 在组件中使用 user store 的方法:
|
||||
*/
|
||||
|
||||
// 1. 导入 store
|
||||
import { useUserStore } from '@/store/user'
|
||||
|
||||
// 2. 在 setup 中使用
|
||||
export default {
|
||||
setup() {
|
||||
const userStore = useUserStore()
|
||||
|
||||
// 获取 token
|
||||
const token = userStore.getToken
|
||||
|
||||
// 判断是否登录
|
||||
const isLogin = userStore.isLogin
|
||||
|
||||
// 设置 token
|
||||
userStore.setToken('your-token-here')
|
||||
|
||||
// 登录
|
||||
userStore.login('your-token-here', {
|
||||
id: 1,
|
||||
name: '用户名',
|
||||
avatar: '头像地址'
|
||||
})
|
||||
|
||||
// 退出登录
|
||||
userStore.logout()
|
||||
|
||||
return {
|
||||
token,
|
||||
isLogin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 或者使用 Composition API
|
||||
import { computed } from 'vue'
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
const userStore = useUserStore()
|
||||
|
||||
// 使用 getter
|
||||
const isLogin = computed(() => userStore.isLogin)
|
||||
const token = computed(() => userStore.getToken)
|
||||
|
||||
// 调用 action
|
||||
const handleLogin = () => {
|
||||
userStore.login('token-123', {
|
||||
id: 1,
|
||||
name: '张三'
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
isLogin,
|
||||
token,
|
||||
handleLogin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 在 script setup 中使用
|
||||
// <script setup>
|
||||
// import { useUserStore } from '@/store/user'
|
||||
//
|
||||
// const userStore = useUserStore()
|
||||
// const token = userStore.getToken
|
||||
// const isLogin = userStore.isLogin
|
||||
//
|
||||
// // 登录
|
||||
// userStore.login('token', userInfo)
|
||||
//
|
||||
// // 退出
|
||||
// userStore.logout()
|
||||
// </script>
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ export const Request = () => {
|
|||
// 初始化请求配置
|
||||
uni.$uv.http.setConfig((config) => {
|
||||
/* config 为默认全局配置*/
|
||||
config.baseURL = 'http://192.168.1.12:4001'; /* 根域名 */
|
||||
config.baseURL = 'http://192.168.1.7:4001'; /* 根域名 */
|
||||
return config
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user