123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <template>
- <div class="null" v-if="data.length === 0">no information...</div>
- <div class="SearchVisit" v-else>
- <div
- class="row"
- v-for="item in data"
- :key="item.id"
- @click="skip(item.path)"
- >
- <h3 v-html="item.h3"></h3>
- <p v-html="item.p"></p>
- </div>
- </div>
- </template>
- <script>
- import { Visit } from "./data";
- export default {
- name: "SearchVisit",
- components: {},
- data() {
- //这里存放数据
- return {
- data: [],
- };
- },
- //监听属性 类似于data概念
- computed: {},
- //监控data中的数据变化
- watch: {
- $route() {
- this.getData(this.$route.params.t);
- },
- },
- //方法集合
- methods: {
- // 点击跳转,新窗口打开
- skip(path) {
- window.open(path, "_blank");
- },
- // 封装一个获取数据的方法
- getData(txt) {
- if (txt.trim() === "" || txt.trim().length < 4 || txt === "null") {
- this.data = [...Visit];
- } else {
- let temp = [];
- temp = Visit.filter((v) => {
- return v.h3.includes(txt) || v.p.includes(txt);
- });
- //
- temp = temp.map((v) => {
- return {
- ...v,
- h3: v.h3.replaceAll(txt, `<span style='color:red;'>${txt}</span>`),
- p: v.p.replaceAll(txt, `<span style='color:red;'>${txt}</span>`),
- };
- });
- this.data = [...temp];
- }
- this.$emit("update:num", this.data.length);
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {
- this.getData(this.$route.params.t);
- },
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {},
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='less' scoped>
- .null {
- font-family: Bold;
- font-size: 30px;
- margin-top: 50px;
- text-align: center;
- }
- .SearchVisit {
- .row {
- padding: 10px;
- margin-bottom: 10px;
- background-color: #fff;
- box-shadow: 0px 1px 2px 2px #ccc;
- & > h3 {
- margin-bottom: 5px;
- font-size: 16px;
- }
- & > p {
- color: #6A6A6A;
- font-size: 14px;
- line-height: 16px;
- display: -webkit-box;
- overflow: hidden;
- white-space: normal !important;
- text-overflow: ellipsis;
- word-wrap: break-word;
- -webkit-line-clamp: 4;
- -webkit-box-orient: vertical;
- }
- }
- }
- </style>
|