Browse Source

添加友情链接

asd123a20 3 years ago
parent
commit
e861a1ae29

BIN
src/assets/banner/26025416.png


BIN
src/assets/foot/y1.png


BIN
src/assets/foot/y2.png


BIN
src/assets/foot/y3.png


BIN
src/assets/foot/y4.png


+ 14 - 35
src/components/foot/links.vue

@@ -2,7 +2,7 @@
   <div class="linkbox">
     <span>友情链接</span>
     <div class="imgbox">
-      <a v-for="(item, index) in list" :key="index" :href="item.links">
+      <a v-for="(item, index) in linkList" :key="index" :href="item.links">
         <img class="item" :src="item.path" :alt="item.name">
       </a>
     </div>
@@ -10,48 +10,27 @@
 </template>
 
 <script>
+import { createNamespacedHelpers } from 'vuex'
+const { mapState, mapActions } = createNamespacedHelpers('links')
 export default {
   components: {},
   data () {
-    return {
-      list: [
-        {
-          name: '友情链接1',
-          path: require('../../assets/foot/y1.png'),
-          links: 'http://baidu.com'
-        },
-        {
-          name: '友情链接2',
-          path: require('../../assets/foot/y2.png'),
-          links: 'http://youku.com'
-        },
-        {
-          name: '友情链接3',
-          path: require('../../assets/foot/y3.png'),
-          links: 'http://taobao.com'
-        },
-        {
-          name: '友情链接4',
-          path: require('../../assets/foot/y4.png'),
-          links: 'http://4399.com'
-        },
-        {
-          name: '友情链接2',
-          path: require('../../assets/foot/y2.png'),
-          links: 'http://youku.com'
-        }
-      ]
-    }
+    return {}
   },
   methods: {
+    ...mapActions(['getlink']),
     times () {
-      const a = this.list[0]
-      this.list.splice(0, 1)
-      this.list.push(a)
+      const a = this.linkList[0]
+      this.linkList.splice(0, 1)
+      this.linkList.push(a)
     }
   },
-  mounted () {
-    setInterval(this.times, 2000)
+  async mounted () {
+    await this.getlink()
+    setInterval(this.times, 5000)
+  },
+  computed: {
+    ...mapState(['linkList'])
   }
 }
 </script>

+ 3 - 1
src/store/index.js

@@ -5,6 +5,7 @@ import column from './column'
 import content from './content'
 import page from './page'
 import banner from './banner'
+import links from './links'
 Vue.use(Vuex)
 
 export default new Vuex.Store({
@@ -19,6 +20,7 @@ export default new Vuex.Store({
     column,
     content,
     page,
-    banner
+    banner,
+    links
   }
 })

+ 20 - 0
src/store/links.js

@@ -0,0 +1,20 @@
+import axios from 'axios'
+const api = {
+  query: '/api/links/query'
+}
+const state = {
+  linkList: []
+}
+const mutations = {
+  link (state, payload) {
+    state.linkList = payload
+  }
+}
+const actions = {
+  async getlink ({ commit }, payload) {
+    const res = await axios.get(api.query)
+    if (res.data.errcode === 0) commit('link', res.data.data)
+    return res
+  }
+}
+export default { state, mutations, actions, namespaced: true }

+ 1 - 2
src/views/details.vue

@@ -50,8 +50,7 @@ export default {
   async mounted () {
     const res = await this.getmenu()
     if (res.data.errcode === 0) this.filteritem()
-    console.log(this.$router)
-    // await this.getdetails({ id: this.id })
+    await this.getdetails({ id: this.id })
   },
   computed: {
     ...mapState(['items']),