kgc新闻

(src/router/index.js)

import Vue from 'vue'

import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [

 {

   path:'/',

   component:()=>import('../views/index.vue')

 },

 {

   path:'/channelManage',

   component:()=>import('../views/channelManage.vue')

 }

]

const router = new VueRouter({

  routes

})

export default router

(src/main.js)

import Vue from 'vue'

import App from './App.vue'

import router from './router'

import store from './store'

Vue.config.productionTip = false

import axios from 'axios'

Vue.prototype.$axios = axios

new Vue({

  router,

  store,

  render: h => h(App)

}).$mount('#app')

(src/views/index.vue)

<template>

<div>

  <vNav></vNav>

  <div class="main">

    <div v-for="(item,index) in news" :key="index" class="item">

      <img :src="item.pic">

      <div class="right">

        <div class="title">{{item.title}}</div>

        <div class="bottom">

          <div class="time">{{item.time}}</div>

          <div class="type">{{item.src}}</div>

        </div>

      </div>

    </div>

  </div>

</div>

</template>

<script>

import vNav from '../components/vNav.vue'

export default {

  components:{

    vNav

  },

  data() {

    return {

      news:[]

    }

  },

  mounted() {

    this.$axios.get('json/news.json').then(({data:{result:{list}}})=>{

      this.news = list

    })

  },

}

</script>

<style scoped lang='scss'>

.main{

  font-size: 14px;

 .item{

   padding: 6px;

   display: flex;

   border-bottom: 1px solid #ccc;

   img{

     width: 100px;

     height: 100px;

   }

   .right{

     margin-left: 6px;

     flex: 1;

     display: flex;

     flex-direction: column;

     justify-content: space-between;

     .bottom{

       display: flex;

       justify-content: space-between;

       font-size: 12px;

       color: #666;

     }

   }

 }

}

</style>

(src/App.vue)

<template>

  <div id="app">

    <router-view/>

  </div>

</template>

<script>

import axios from 'axios'

export default {

  mounted() {

    axios.get('json/nav.json').then(({data:{result}})=>{

      this.$store.dispatch('muChannels',result)

    })

  },

}

</script>

<style lang="scss">

*{

  margin: 0;

  padding: 0;

  list-style: none;

  text-decoration: none;

  outline: none;

}

html{

  font-size: 20px;

}

</style>

(src/components/vNav.vue)

<template>

<div class="nav">

  <div class="title">KGC新闻</div>

  <div class="list">

    <ul class="itmes">

      <li v-for="(item,index) in myNav" :key="index">{{item}}</li>

    </ul>

    <div class="add" @click="$router.push('/channelManage')">

      <img src="../assets/images/add.png">

    </div>

  </div>

</div>

</template>

<script>

export default {

  computed:{

    myNav(){

      return this.$store.state.myNav

    }

  }

}

</script>

<style scoped lang='scss'>

.nav{

  font-size: 14px;

  .title{

    height: 1.5rem;

    line-height: 1.5rem;

    background: #d43d3d;

    font-weight: bold;

    color: white;

    text-align: center;

  }

  .list{

    display: flex;

    justify-content: space-between;

    align-items: center;

    height: 1.5rem;

    background: #f4f5f6;

    color: #505050;

    .itmes{

      flex: 1;

      display: flex;

      align-items: center;

      overflow-x: scroll;

      li{

        padding: 0 15px;

        white-space: nowrap;

      }

    }

    .add{

      height: 1.5rem;

      width: 1.5rem;

      img{

        height: 1.5rem;

        width: 1.5rem;

        border-left: 1px solid #ccc;

      }

    }

  }

}

</style>

(src/store/index.js)

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({

  state: {

    allNav:[],

    myNav:[]

  },

  getters: {

  },

  mutations: {

    muChannels(state,val){

      state.allNav = val

    },

    increment(state,val){

      state.myNav.push(state.allNav[val])

      state.allNav.splice(val,1)

    },

    decrement(state,val){

      state.allNav.push(state.myNav[val])

      state.myNav.splice(val,1)

    }

  },

  actions: {

    muChannels(store,val){

      store.commit('muChannels',val)

    },

    increment(store,val){

      store.commit('increment',val)

    },

    decrement(store,val){

      store.commit('decrement',val)

    }

  },

  modules: {

  }

})

(src/views/channelManage.vue)

<template>

  <div class="channel">

    <div class="title">

      <div class="img" @click="$router.push('/')">

        <img src="../assets/images/back.png">

      </div>

      <div class="content">频道管理</div>

    </div>

    <div class="box">

      <div>点击删除以下频道</div>

      <ul>

        <li @click="del(index)" v-for="(item,index) in myNav" :key="index">{{item}}</li>

      </ul>

    </div>

    <div class="box">

      <div>点击添加以下频道</div>

      <ul>

        <li @click="add(index)" v-for="(item,index) in allNav" :key="index">{{item}}</li>

      </ul>

    </div>

  </div>

</template>

<script>

export default {

  computed:{

    myNav(){

      return this.$store.state.myNav

    },

    allNav(){

      return this.$store.state.allNav

    }

  },

  methods: {

    add(index){

      this.$store.dispatch('increment',index)

    },

    del(index){

      this.$store.dispatch('decrement',index)

    }

  },

};

</script>

<style scoped lang="scss">

.channel{

  font-size: 14px;

  .title{

    height: 2rem;

    background: #d43d3d;

    display: flex;

    align-items: center;

    .img{

      padding: 0 5px;

      display: flex;

      align-items: center;

      img{

        width: 1.5rem;

      }

    }

    .content{

      flex: 1;

      font-size: 16px;

      font-weight: bold;

      color: white;

      text-align: center;

    }

  }

  .box{

    padding: 10px;

    ul{

      display: flex;

      flex-wrap: wrap;

      li{

        padding: 2px;

        width: 60px;

        text-align: center;

        border: 1px solid #ccc;

        margin-right: 20px;

        margin-top: 4px;

      }

    }

  }

}

</style>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • HTML部分 你是如何理解 HTML 语义化的? HTML语义化就是使用合适的标签书写合适的内容,避免使用过多无意...
    学的会的前端阅读 3,480评论 0 2
  • 项目开发流程 脚手架 一、自己搭建(公司搭建属于自己的) webpack 二、vue-cli webpack3 三...
    赵赵赵_0c27阅读 656评论 0 0
  • css相关 1. 万能居中 1.margin: 0 auto;水平 2.text-align: center;水平...
    chaocc阅读 4,617评论 0 2
  • <template> <el-form :inline="false" :model="form" ref="...
    南漂一枚阅读 2,682评论 0 0
  • 1、从输入url到浏览器呈现页面中间经历了什么? 在输入url的时候,会进行本地历史记录和标签页的查询,提供模糊查...
    林思念阅读 7,613评论 2 24