当前位置:   article > 正文

Vue在弹出层界面点击链接跳转,并触发跳转页面的刷新以及弹出层的关闭_vue 弹窗弹出如何跳转前关闭

vue 弹窗弹出如何跳转前关闭

需求:

点击弹出的消息链接,跳转到对应的界面,并触发对应界面的刷新。

1.首先找到弹出层界面的代码:

  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="modelStyle.width"
  5. :visible="visible"
  6. :bodyStyle ="bodyStyle"
  7. :switchFullscreen="switchFullscreen"
  8. @cancel="handleCancel"
  9. >
  10. <template slot="footer">
  11. <a-button key="back" @click="handleCancel">关闭</a-button>
  12. <a-button v-if="record.openType==='url'" type="primary" @click="toHandle">去处理</a-button>
  13. </template>
  14. <a-card class="daily-article" :loading="loading">
  15. <a-card-meta
  16. :title="record.titile"
  17. :description="'发布人:'+record.sender + ' 发布时间: ' + record.sendTime">
  18. </a-card-meta>
  19. <a-divider />
  20. <span v-html="record.msgContent" class="article-content"></span>
  21. </a-card>
  22. </j-modal>
  23. </template>
  24. <script>
  25. export default {
  26. name: "SysAnnouncementModal",
  27. components: {
  28. },
  29. data () {
  30. return {
  31. title:"通知消息",
  32. record: {},
  33. labelCol: {
  34. xs: { span: 24 },
  35. sm: { span: 5 },
  36. },
  37. wrapperCol: {
  38. xs: { span: 24 },
  39. sm: { span: 16 },
  40. },
  41. visible: false,
  42. switchFullscreen: true,
  43. loading: false,
  44. bodyStyle:{
  45. padding: "0",
  46. height:(window.innerHeight*0.8)+"px",
  47. "overflow-y":"auto",
  48. },
  49. modelStyle:{
  50. width: '60%',
  51. style: { top: '20px' },
  52. fullScreen: false
  53. }
  54. }
  55. },
  56. inject:['reload'],
  57. created () {
  58. },
  59. methods: {
  60. detail (record) {
  61. this.visible = true;
  62. this.record = record;
  63. },
  64. handleCancel () {
  65. this.visible = false;
  66. },
  67. /** 切换全屏显示 */
  68. handleClickToggleFullScreen() {
  69. let mode = !this.modelStyle.fullScreen
  70. if (mode) {
  71. this.modelStyle.width = '100%'
  72. this.modelStyle.style.top = '20px'
  73. } else {
  74. this.modelStyle.width = '60%'
  75. this.modelStyle.style.top = '50px'
  76. }
  77. this.modelStyle.fullScreen = mode
  78. },
  79. toHandle(){
  80. if(this.record.openType==='url'){
  81. this.visible = false;
  82. //链接跳转
  83. this.$router.push({path: this.record.openPage})
  84. }
  85. },
  86. JumpTo: function(e){
  87. this.visible = false;
  88. if(e.target.nodeName === 'A') {
  89. this.reload();
  90. this.$router.push('/custom/zz_duty_reason/vue/ZzInconformityItemListList')
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="less">
  97. .announcementCustomModal{
  98. .ant-modal-header {
  99. border: none;
  100. display: inline-block;
  101. position: absolute;
  102. z-index: 1;
  103. right: 56px;
  104. padding: 0;
  105. .ant-modal-title{
  106. .custom-btn{
  107. width: 56px;
  108. height: 56px;
  109. border: none;
  110. box-shadow: none;
  111. }
  112. }
  113. }
  114. .daily-article{
  115. border-bottom: 0;
  116. }
  117. }
  118. </style>
  119. <style scoped lang="less">
  120. .daily-article {
  121. .article-button {
  122. font-size: 1.2rem !important;
  123. }
  124. .ant-card-body {
  125. padding: 18px !important;
  126. }
  127. .ant-card-head {
  128. padding: 0 1rem;
  129. }
  130. .ant-card-meta {
  131. margin-bottom: 1rem;
  132. }
  133. .article-content {
  134. p {
  135. word-wrap: break-word;
  136. word-break: break-all;
  137. text-overflow: initial;
  138. white-space: normal;
  139. font-size: .9rem !important;
  140. margin-bottom: .8rem;
  141. }
  142. }
  143. }
  144. </style>

主要看v-html这一块:

<span v-html="record.msgContent" class="article-content"></span>

后台返回的信息为:

sysUtil.sendMsgToResp(entity.getResponsibleDepartment(),"您收到一条'不符合事项报告',报告编号为:<a>"+zzInconformityItem.getReportNo() +"</a>");可以

可以看到返回的消息带a标签,之后要根据a标签的内容去跳转页面。因此需要在前端代码页加上一个动作:

<span v-html="record.msgContent" class="article-content" @click="JumpTo($event)"></span>

这个@click即表示要点击触发的动作。

JumpTo: function(e){
  this.visible = false;//关闭当前弹出层
  if(e.target.nodeName === 'A') {
    this.reload();//刷新对应页面
    this.$router.push('/custom/zz_duty_reason/vue/ZzInconformityItemListList')//页面跳转
  }
}

至此已经实现页面跳转和当前弹出层的关闭。还差一个刷新对应的页面。

2.App.Vue中的代码增加:

  1. <template>
  2. <a-config-provider :locale="locale">
  3. <div id="app" v-if="isRouterAlive">
  4. <router-view/>
  5. </div>
  6. </a-config-provider>
  7. </template>
  8. <script>
  9. import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
  10. import enquireScreen from '@/utils/device'
  11. export default {
  12. data () {
  13. return {
  14. locale: zhCN,
  15. isRouterAlive: true
  16. }
  17. },
  18. provide() {
  19. return {
  20. reload: this.reload
  21. }
  22. },
  23. created () {
  24. let that = this
  25. enquireScreen(deviceType => {
  26. // tablet
  27. if (deviceType === 0) {
  28. that.$store.commit('TOGGLE_DEVICE', 'mobile')
  29. that.$store.dispatch('setSidebar', false)
  30. }
  31. // mobile
  32. else if (deviceType === 1) {
  33. that.$store.commit('TOGGLE_DEVICE', 'mobile')
  34. that.$store.dispatch('setSidebar', false)
  35. }
  36. else {
  37. that.$store.commit('TOGGLE_DEVICE', 'desktop')
  38. that.$store.dispatch('setSidebar', true)
  39. }
  40. })
  41. },
  42. methods: {
  43. reload() {
  44. this.isRouterAlive = false
  45. this.$nextTick(() => {
  46. this.isRouterAlive = true
  47. })
  48. }
  49. }
  50. }
  51. </script>
  52. <style>
  53. #app {
  54. height: 100%;
  55. }
  56. </style>

 

3.在对应界面加上:

这些代码加载消息弹出层本界面,而不是对应的被跳转的页面。

参考:

vue router跳转页面后刷新 跳转后的页面_曾令胜的博客-CSDN博客_vue 刷新跳转后的页面

vue在v-html中绑定事件_fangdengfu123的博客-CSDN博客_v-html 事件

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/106726
推荐阅读
相关标签
  

闽ICP备14008679号