首页 > 其他分享 >vue3点击其他元素隐藏固定DIV

vue3点击其他元素隐藏固定DIV

时间:2022-11-17 11:46:06浏览次数:47  
标签:const 元素 value 点击 cliFun proxy vue3 DIV 隐藏

vue3点击其他元素隐藏固定DIV

显示的内容

 <div v-if="hSearch" ref="iscity">
    <div><input class="h-9 w-full" placeholder="内容搜索..." /></div>  
  </div>

元素函数

export const hSearch = ref(false) //是否显示搜素框
export const hSearchValue = ref('') //搜素事件是否存在

const proxy: any = getCurrentInstance()
const cliFun = (e: any) => {
  if (!proxy.ctx.$refs.iscity.contains(e.target) && e.target.id !== 'iscity') {
    if (hSearchValue.value.contains(e.target)) return //如果存在元素不隐藏
    hSearch.value = false //隐藏
  }
}
onMounted(() => {
  document.addEventListener('click', cliFun) //点击事件
})
onUnmounted(() => {
  document.removeEventListener('click', cliFun) //删除事件
})

父元素内容

<input ref="ipu" type="text" @focus="test" />
const proxy: any = getCurrentInstance()
function test() {
  hSearchValue.value = proxy.ctx.$refs.ipu //如果存在不隐藏
  hSearch.value = true  //显示元素内容
}

标签:const,元素,value,点击,cliFun,proxy,vue3,DIV,隐藏
From: https://www.cnblogs.com/ouyangkai/p/16898938.html

相关文章

  • vue3的<setup script>中使用異步函數
    由於vue3的setup一般情況下不允許為async,如果要將setup變成async,則要引入異步組件 <Suspense> <template#default> <SwitchMaintenanceUpdate/> </template> </S......
  • Vue和Vue3在VS中的插件
     Vue的插件vetur vetur和Vue3插件VuelanguageFeature冲突,只能用一个   Vue3的插件volarVuelanguageFeature和Vue插件Vetur冲突,只能用一个 ......
  • Vue3(Mitt)
     Vue3+vite+Ts+pinia+实战+源码+全栈_哔哩哔哩_bilibili视频教程在vue3中$on,$off和$once实例方法已被移除,组件实例不再实现事件触发接口,因此大家熟悉的E......
  • 手动实现 vue3 [ reactive, computed, watch ]
    一、vue.js1importreactivefrom"./reactive";2importWatcherfrom"./Watcher";3importcomputedfrom"./computed";4importwatchfrom"./watch";56ex......
  • Codeforces Round #833 (Div. 2) D
    D.ConstructOR转化题意a|x=k1db|x=k2d我们考虑k1k2同样就只用让x包含a|b对于a|b的每一位我们用d的最后一位来填补然后在线的要是a|b这里有我们的x没有显然要让......
  • JavaScript中点击按钮弹出新的浏览器窗口
    */*Copyright(c)2016,烟台大学计算机与控制工程学院*Allrightsreserved.*文件名:text.js*作者:常轩*微信公众号:Worldhello*完成日期:2016年10月226日*版本号:V......
  • WPF 点击DataGrid中按钮无触发
    上干货<DataGridTemplateColumnHeader="操作"Width="1*"><DataGridTemplateColumn.CellTemplate>......
  • VUE3 elment-ui el-tabel遍历实现表格的自定义列【KEY值为列名】
    <template><div><el-table:data="resultTable"borderref="multipleTable"tooltip-effect="light"size="mini"><el-table-columntype="i......
  • Vue.js devtools插件点击Root失效或不显示数据问题的解决方法
    原文链接:https://blog.csdn.net/m0_59183852/article/details/126981557刚开始用这个插件,我就遇到了一个问题:使用该插件对代码进行调试的时候,发现如何点击<Root>都没有反......
  • Vue3的setup在el-tab中动态加载组件
    公司某项目需求在页面显示的组件是根据角色变化而变化的,在这个项目中我使用了elementplus的el-tabs来动态的显示这些组件,如下图所示数据内容大概是这样的在未使用setup......