fix(component): 修复组件名称错误和props类型定义
refactor(component): 重构组件模板结构,移除重复代码 feat(component): 添加可选props支持外部数据传入 style(css): 优化样式布局和响应式设计 fix(js): 修复URL路径处理逻辑和滚动加载问题 feat(search): 新增搜索页推荐内容和空状态处理 chore: 添加新图标资源文件
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
// my-component.js
|
||||
// 引入全局 Vue 对象(因在 HTML 中通过 script 引入,Vue 已挂载到 window)
|
||||
const { defineComponent, ref, onMounted } = Vue;
|
||||
const { defineComponent, ref, onMounted, emit, watch } = Vue;
|
||||
// 定义组件(直接使用模板)
|
||||
export const hotTag = defineComponent({
|
||||
name: "hot-tag",
|
||||
props: {},
|
||||
props: {
|
||||
isnorequestdata: {
|
||||
type: Boolean,
|
||||
},
|
||||
taglist: {
|
||||
type: Array,
|
||||
},
|
||||
},
|
||||
|
||||
setup(props) {
|
||||
let valueUrl = ref("");
|
||||
|
||||
onMounted(() => {
|
||||
init();
|
||||
if (!props.isnorequestdata) init();
|
||||
const valueA = document.querySelector(".valueA");
|
||||
valueUrl.value = valueA.innerText;
|
||||
});
|
||||
@@ -24,10 +31,22 @@ export const hotTag = defineComponent({
|
||||
|
||||
const list = ref([]);
|
||||
|
||||
watch(
|
||||
() => props.taglist,
|
||||
(newVal) => {
|
||||
if (newVal) list.value = newVal;
|
||||
},
|
||||
{
|
||||
deep: true, // 核心:开启深度监听(监听对象/数组内部属性变化)
|
||||
immediate: true, // 可选:组件挂载时立即执行一次回调(根据需求决定)
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return { valueUrl, list };
|
||||
},
|
||||
|
||||
components: {},
|
||||
|
||||
template: `<div class="hot-tag" v-if="list.length > 0"> <div class="hot-tag-title"> <img class="icon" :src="valueUrl + '/img/triangle-orange.svg'" /> 热门标签 </div> <div class="list flexflex"> <a class="item" v-for="item in list" :href="'/tag/' + item.tagname" target="_blank">{{ item.tagname }}</a> </div></div>`,
|
||||
template: `<div class="hot-tag" v-if="list?.length > 0"> <div class="hot-tag-title"> <img class="icon" :src="valueUrl + '/img/triangle-orange.svg'" /> 热门标签 </div> <div class="list flexflex"> <a class="item" v-for="item in list" :href="'/tag/' + item.tagname" target="_blank">{{ item.tagname }}</a> </div></div>`,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="hot-tag" v-if="list.length > 0">
|
||||
<div class="hot-tag" v-if="list?.length > 0">
|
||||
<div class="hot-tag-title">
|
||||
<img class="icon" :src="valueUrl + '/img/triangle-orange.svg'" />
|
||||
热门标签
|
||||
|
||||
Reference in New Issue
Block a user