Visit.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="null" v-if="data.length === 0">no information...</div>
  3. <div class="SearchVisit" v-else>
  4. <div
  5. class="row"
  6. v-for="item in data"
  7. :key="item.id"
  8. @click="skip(item.path)"
  9. >
  10. <h3 v-html="item.h3"></h3>
  11. <p v-html="item.p"></p>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import { Visit } from "./data";
  17. export default {
  18. name: "SearchVisit",
  19. components: {},
  20. data() {
  21. //这里存放数据
  22. return {
  23. data: [],
  24. };
  25. },
  26. //监听属性 类似于data概念
  27. computed: {},
  28. //监控data中的数据变化
  29. watch: {
  30. $route() {
  31. this.getData(this.$route.params.t);
  32. },
  33. },
  34. //方法集合
  35. methods: {
  36. // 点击跳转,新窗口打开
  37. skip(path) {
  38. window.open(path, "_blank");
  39. },
  40. // 封装一个获取数据的方法
  41. getData(txt) {
  42. if (txt.trim() === "" || txt.trim().length < 4 || txt === "null") {
  43. this.data = [...Visit];
  44. } else {
  45. let temp = [];
  46. temp = Visit.filter((v) => {
  47. return v.h3.includes(txt) || v.p.includes(txt);
  48. });
  49. //
  50. temp = temp.map((v) => {
  51. return {
  52. ...v,
  53. h3: v.h3.replaceAll(txt, `<span style='color:red;'>${txt}</span>`),
  54. p: v.p.replaceAll(txt, `<span style='color:red;'>${txt}</span>`),
  55. };
  56. });
  57. this.data = [...temp];
  58. }
  59. this.$emit("update:num", this.data.length);
  60. },
  61. },
  62. //生命周期 - 创建完成(可以访问当前this实例)
  63. created() {
  64. this.getData(this.$route.params.t);
  65. },
  66. //生命周期 - 挂载完成(可以访问DOM元素)
  67. mounted() {},
  68. beforeCreate() {}, //生命周期 - 创建之前
  69. beforeMount() {}, //生命周期 - 挂载之前
  70. beforeUpdate() {}, //生命周期 - 更新之前
  71. updated() {}, //生命周期 - 更新之后
  72. beforeDestroy() {}, //生命周期 - 销毁之前
  73. destroyed() {}, //生命周期 - 销毁完成
  74. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  75. };
  76. </script>
  77. <style lang='less' scoped>
  78. .null {
  79. font-family: Bold;
  80. font-size: 30px;
  81. margin-top: 50px;
  82. text-align: center;
  83. }
  84. .SearchVisit {
  85. .row {
  86. padding: 10px;
  87. margin-bottom: 10px;
  88. background-color: #fff;
  89. box-shadow: 0px 1px 2px 2px #ccc;
  90. & > h3 {
  91. margin-bottom: 5px;
  92. font-size: 16px;
  93. }
  94. & > p {
  95. color: #6A6A6A;
  96. font-size: 14px;
  97. line-height: 16px;
  98. display: -webkit-box;
  99. overflow: hidden;
  100. white-space: normal !important;
  101. text-overflow: ellipsis;
  102. word-wrap: break-word;
  103. -webkit-line-clamp: 4;
  104. -webkit-box-orient: vertical;
  105. }
  106. }
  107. }
  108. </style>