当前位置:网站首页>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>
边栏推荐
猜你喜欢
随机推荐
【系统架构设计师】第三章 数据库系统
我为什么又能面试一次就拿到offer
程序员英语自我介绍
升级版的冒泡排序:鸡尾酒排序(快乐小时排序)
十二、form表单的提交
如何使用vlookup+excel数组公式 完成逆向查找?
几种常见的跨域解决方法
可编程逻辑控制器(PLC) : 基础、类型和应用
CIO修炼手册:成功晋升CIO的七个秘诀
十三、数据回显
基于rt-thread studio的STM32裸机开发——LED
浅谈I2C知识
用了 TCP 协议,数据一定不会丢吗?
解决错误:Optional int parameter ‘pageSize‘ is present but cannot be translated into a null value due to
用了TCP协议,就一定不会丢包吗?
# DWD层及DIM层构建## ,220801 ,
random.nextint()详解
2022山东国际青少年眼睛健康产业展会,视力健康展,眼视光展
嵌入式分享合集26
HVV红队 | 渗透测试思路整理









