// my-component.js // 引入全局 Vue 对象(因在 HTML 中通过 script 引入,Vue 已挂载到 window) const { defineComponent, ref } = Vue; import { itemBottom } from "../item-bottom/item-bottom.js"; import { itemHead } from "../item-head/item-head.js"; // 定义组件(直接使用模板) export const itemTenement = defineComponent({ name: "item-tenement", props: { itemdata: { type: Object, default: () => {}, }, }, setup(props) { const handleHousing = (ele) => { const langs = lang; console.log("langs", langs); if (ele["distance"]) ele["distance"] = Math.round(ele["distance"] * 10) / 10; // 这个是将 详情键 替换语言包里的值 let list = ["tenementtype", "rentalduration", "intermediary", "property", "elevator", "sunshinearea", "gender"]; // let list = ["rentalduration", "intermediary", "property", "elevator", "sunshinearea", "gender"]; if (Array.isArray(ele["floor"])) list.push("floor"); // 判断 楼层是否需要 替换值, 因为在求房源里是多个值 let differentNames = { // 需要替换的 键名 intermediary: "intermediary_text", }; list.forEach((element) => { if (ele[element] == -1) { } else if (ele[element] == 0) ele[differentNames[element] ? differentNames[element] : element] = "不限"; // 当 值为 [0] 时为不限 else ele[differentNames[element] ? differentNames[element] : element] = langs[element][ele[element]]; }); let tabArr = ["gptype", "tenementtype", "elevator", "sunshinearea", "gender"]; let tabList = []; tabArr.forEach((el) => { if (ele[el] && ele[el] != -1) tabList.push(ele[el]); }); ele["tabList"] = tabList; let location = langs.location; // 遍历替换区域的值 所有房源 if (ele.intermediary == 6) { if (Array.isArray(ele.rent)) ele.rent = `${ele.rent[0]} ~ ${ele.rent[1]}`; if (Array.isArray(ele["location"])) { let arr = []; ele["location"].forEach((element) => { arr.push(`${location[Math.trunc(element)]} > ${location[element]}`); }); ele["location"] = arr; } } else { let pendingData = ele["location"]; ele["location"] = `${location[Math.trunc(pendingData)]} > ${location[pendingData]}`; } return ele; }; let item = ref({ ...props.itemdata }); // console.log("item", item.value); item.value = handleHousing(item.value); console.log("item.value", item.value); return { item }; }, components: { itemBottom, itemHead, }, template: `
三房找一位室友合租,家具设备齐全
{{ item.location || '九龙 > 尖沙咀/佐敦' }}
HK$
{{ item.rent }}
/月
[ 租期{{ item.rentalduration }} ]
`, });