Files
2026-09-20 15:46:34 +08:00

40 lines
1.2 KiB
JavaScript

const news = {
template: `
<div class="home-news">
<el-tabs v-model="activeName">
<el-tab-pane v-for="(item,index) in newsData" :key="index" :label="item.label" :name="item.label" v-if="item.value.length > 0">
<div v-for="(n,i) in item.value" :key="i" @click="openUrl(n.href)">
<span v-if="n.time" class="news_time">{{ n.time }}</span>
<span class="news_text">{{ n.text }}</span>
</div>
</el-tab-pane>
</el-tabs>
</div>
`,
data() {
return {
newsData: [],
activeName: 0
}
},
methods: {
async getNews() {
const resp = await $.post("/platform/home/getNews")
if (resp.data.length > 0) {
this.activeName = resp.data[0].label
}
this.newsData = resp.data
},
openUrl(href) {
const url = this.isHttpOrHttps(href) ? href : "https://gonghui.hhu.edu.cn/" + href
window.open(url)
},
isHttpOrHttps(url) {
return /^(http:\/\/|https:\/\/)/i.test(url)
}
},
async created() {
await this.getNews()
}
}