About.vue 2.8 KB

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