Employment.vue 3.2 KB

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