About.vue 2.7 KB

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