当前位置:网站首页>vue3的keepAlive缓存组件
vue3的keepAlive缓存组件
2022-08-02 23:44:00 【@小朱呀路】


新建login.vue
<template>
<div>login 此界面的输入框的东西切换回来就没了
<input type="text">
<input type="text">
<button @click="submit">登陆</button>
</div>
</template>
<script setup lang="ts">
</script>
<script >
export default{
name:'login'
}
</script>
<style scoped>
</style>
新建insert.vue
<template>
<div>insert 无论切换都会保留input的内容
<input type="text" v-model="data.reform.text">
<input type="text" v-model="data.reform.password">
<input type="text" v-model="data.reform.code">
<button @click="submit">注册</button>
</div>
</template>
<script setup lang="ts">
import {
reactive,onActivated} from 'vue'
type refo={
reform:{
text:string,
password:string,
code:string
}
}
let data=reactive<refo>({
reform:{
text:"",password:'',code:''}
})
onActivated(()=>{
data.reform.code=''
})
</script>
<style scoped>
</style>
父组件引入
<template>
<div class="content">
<button @click="slectadd">切换</button>
<keep-alive :exclude="['login']">
<login v-if="flag"/>
<insert v-else/>
</keep-alive>
</div>
</template>
<script setup lang="ts">
import {
reactive ,markRaw,ref} from 'vue'
import login from '../../components/login/index.vue'
import insert from '../../components/insert/index.vue'
const flag=ref(true);
const slectadd=()=>{
flag.value=!flag.value
}
</script>
<style scoped lang="less">
.bg-red{
background: red;
}
.content{
flex: 1;
display: flex;
// height: 100vh;
margin: 20px;
border-bottom: 1px solid #ccc;
overflow: auto;
&-items{
padding:20px;border-bottom: 1px solid #ffffff;
}
.tab{
height: 50px;
border:1px solid red;
}
component{
height: 30px;;
}
}
</style>
边栏推荐
猜你喜欢
随机推荐
Canonical correlation analysis of CCA calculation process
Controller层代码这么写,简洁又优雅!
Rasa 3.x 学习系列- Rasa - Issues 4792 socket debug logs clog up debug feed学习笔记
Numpy数组中d[True]=1的含义
用了 TCP 协议,数据一定不会丢吗?
2022山东国际青少年眼睛健康产业展会,视力健康展,眼视光展
用了这么多年的LinkedList,作者说自己从来不用它?为什么?
Let's talk about the charm of code language
华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
聚乙二醇衍生物4-Arm PEG-DSPE,四臂-聚乙二醇-磷脂
Day117. Shangyitong: Generate registered order module
Nacos配置中心之事件订阅
脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3
Pytest配置项-pytest.ini
优秀论文以及思路分析01
nmap: Bad CPU type in executable
Moco of Mock tools use tutorial
matplotlib中的3D绘图警告解决:MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure
电压传感器: 工作原理、类型及电路图
为了面试阿里,熬夜肝完这份软件测试笔记后,Offer终于到手了









