// my-component.js // 引入全局 Vue 对象(因在 HTML 中通过 script 引入,Vue 已挂载到 window) const { defineComponent, ref, onMounted } = Vue; // 定义组件(直接使用模板) export const hotSearch = defineComponent({ name: "hot-search", props: {}, setup(props) { let valueUrl = ref(""); onMounted(() => { init(); const valueA = document.querySelector(".valueA"); valueUrl.value = valueA.innerText; }); const init = () => { ajaxGet("/v2/api/forum/getHotSearchWords?limit=20").then((res) => { const data = res.data; list.value = data || []; }); }; const list = ref([]); return { valueUrl, list }; }, components: {}, template: `
热门搜索
{{ item.keyword }}
`, });