首页 > 其他分享 >el-dialog每次重新打开展示不同的内容,滚动条未重新置顶的解决方案。

el-dialog每次重新打开展示不同的内容,滚动条未重新置顶的解决方案。

时间:2023-04-13 20:44:15浏览次数:39  
标签:el newsDialog 滚动条 null data 置顶

环境

nuxt3 + vu3 + element-plus-2.3.3

复现原因

假设有5条内容,打开一项内容通过el-dialog进行展示,当出现滚动条后,往下滑动,紧接着通过esc或遮罩进行关闭,打开另一项内容,这时候滚动条并未进行置顶。

解决方法

参考就行了。

js部分

const data = reactive({
  newsDialog: {
    show: false,
    currentNews: null,
  }
})

const refNewsDialog = ref(null);
watchEffect( ()=> {
  if(data.newsDialog.currentNews !== null){
    console.log("打开对话框", data.newsDialog.currentNews)
    data.newsDialog.show = true;
    nextTick(() => {
      // 滚动条重置
      ==refNewsDialog.value.dialogContentRef.$el.parentElement.scroll(0,0);==
    })
  }
})

模板部分

    <client-only>
      <el-dialog
          destroy-on-close ref="refNewsDialog" v-model="data.newsDialog.show" :show-close="true" @closed="data.newsDialog.currentNews = null" width="80%" class="news-dialog">
        <template #header="{ close, titleId, titleClass }">
          <div class="header">
            <h4 :id="titleId" :class="titleClass" v-text="data.newsDialog.currentNews.title"></h4>
          </div>
        </template>
        <div class="news-content" v-html="data.newsDialog.currentNews.content"></div>
      </el-dialog>
    </client-only>

总结

vue3因为对组件有更精细的控制暴露出的对象信息,这导致了element-plus2版本暴露出的有用对象太少了。真是太难了。

标签:el,newsDialog,滚动条,null,data,置顶
From: https://www.cnblogs.com/XingXiaoMeng/p/17316351.html

相关文章

  • 【element-ui】解决textarea show-word-limit挡住文字问题
    问题:“67/500”默认背景为白色已超出文本输入框,遮住部分上border,当文字到达右侧时会遮住部分文字,且无法点击该部分解决方案:背景透明色,文字放到右下角 html:<el-inputtype="textarea"autosize maxlength="500"show-word-limit v-model="form.keyIndustry"placeh......
  • 【element-ui】element ui from表单手机号座机号验证
    //手机号验证rules:{ phone:[ {required:true,min:11,max:11,message:"请输入11位手机号码",trigger:"blur"},{pattern:/^1[3456789]\d{9}$/,message:"请输入正确的手机号码"}]}//座机号......
  • 【Azure Developer】使用 Microsoft Graph API 获取 AAD User 操作示例
    问题描述查看官方文档“ Getauser ”,产生了一个操作示例的想法,在中国区Azure环境中,演示如何获取AADUser信息。 问题解答使用MicrosoftGraphAPI,演示如何获取AADUser信息,因参考文档是针对GlobalAzure,所以文档种的URL为://GlobalAzureMicrosoftGraphAPIHostG......
  • Java POI 拆分excel单元格并填充内容
    publicvoidtest(Sheetsheet){intnumMergedRegions=sheet.getNumMergedRegions();for(intz=0;z<numMergedRegions;z++){CellRangeAddressmerge=sheet.getMergedRegion(z);//System.out.println("Numbe......
  • 66、K8S-部署管理-Helm-自定义helm项目
    1、自定义helm项目管理-实践1.1、自定义helm项目1.1.1、创建存放的目录mkdir-p/opt/custom_helm&&cd/opt/custom_helm1.1.2、创建helm项目helmcreatenginx1.2.3、目录的解析custom_helm]#treenginx/nginx/-自动生成的空ch......
  • 一次第三方访问不了系统且telnet端口不通的排查
    最近在测试环境与第三方安全厂商测试联调,对方反馈访问不了系统且telnet端口也不通,确认云服务器安全组和服务器防火墙均已正确配置放行策略,而且我放系统已运行一段时间,各办公网络通过访问正常,telnet也正常,初步判断应该不是我方系统问题,但是得证明不是我们这边问题,于是用tcpdump抓......
  • Element Plus Tree 树 回显
     <el-form-itemlabel="菜单权限">       <el-tree:data="navList"ref="treeRef"  node-key="menuId"highlight-current=“true”:props="defaultProps" @check="checked" show-checkboxcl......
  • selenium操作网页再练手
    #coding:utf-8fromselenium.commonimportNoSuchElementException,TimeoutExceptionfromselenium.webdriver.supportimportexpected_conditionsasECfromtkinterimport*importthreadingfromtkinterimportttkimportpandasaspdfromselenium.webdriver......
  • nfs via ssh tunnel(通过ssh隧道跨网络挂载nfs)
    这篇代码段帮了大忙:https://gist.github.com/proudlygeek/5721498下面给出我的设置:我要在机器97上访问机器231上的硬盘,需要把231上的/data1/ubuntu挂载到97上1.共享nfs文件夹在231上编辑:/etc/exports(需要root)ubuntu@lthpc:~$cat/etc/exports/data1/ubuntulocalhost(ins......
  • windows上编写shell拷到linux执行报错
    1.最近随手在windows写了个自动安装docker的shell脚本,然后传到linux服务器执行竟然报以下错  2.进入vim查看突然看到下截图红色框地方 最后查阅资料发现,这个标志的产生原因是因为在windows下,文件的换行符是\r\n,而在linux下换行符是\n,所以,使用cat-Ainstall_docker.sh......