<template>
<div class="box">
<header class="header">分类头部</header>
<div class="content">
<div class="kind">
<div class="left">
<ul>
<li :class="kindindex === index ? 'active' : ''" v-for="(item, index) of kindlist" @click="getBrand(item, index)" :key="index">{{ item }}</li>
</ul>
</div>
<div class="right">
<div class="top">
<ul>
<li :class="brandindex === index ? 'active' : ''" v-for="(item, index) of brandlist" :key = "index" @click="getlist(item, index)">
<!-- <img :src="item.barndimg" alt=""> -->
{{ item.brand }}
</li>
</ul>
</div>
<Prolist :prolist = "prolist"/>
</div>
</div>
</div>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
import Prolist from '@/components/Prolist'
export default {
components: {
Prolist
},
computed: {
...mapState({
kindlist: ({ kind: { kindlist } }) => kindlist,//kind=state.kind;kindlist=state.kind.kindlist
brandlist: (state) => state.kind.brandlist,
prolist: ({ kind }) => kind.prolist //kind=state.kind
})
},
data () {
return {
kindindex: 0,
brandindex: 0
}
},
created () {
// this.$store.dispatch('getKindlist').then(data => {
// if (data === 0) {
// this.$router.push('/login')
// } else {
// this.getBrand(this.kindlist[0], 0)
// }
// })
this.getKindlist().then(data => {
if (data === 0) {
this.$router.push('/login')
} else {
this.getBrand(this.kindlist[0], 0)
}
})
},
methods: {
...mapActions({
getKindlist: 'kind/getKindlist' // 自动生成一个函数 this.$store.dispatch('getKindlist') key值为组件自定义的函数,value为状态管理器action的名字,在需要的地方触发 自定义的函数即可
}),
getBrand (item, index) {
this.kindindex = index
this.brandindex = 0
this.$store.dispatch('kind/getBrandlist', { item }).then(data => {
if (data === 0) {
this.$router.push('/login')
} else {
this.getlist(this.brandlist[0], 0)
}
})
},
getlist (item, index) {
console.log('item', item)
this.brandindex = index
this.$store.dispatch('kind/getProlist', { brand: item.brand }).then(data => {
if (data === 0) {
this.$router.push('/login')
}
})
}
}
}
</script> <style lang="scss">
@import '@/lib/reset.scss';
.content {
.kind {
@include rect(100%, 100%);
@include flexbox();
.left {
@include rect(1rem, 100%);
@include border(0 1px 0 0, #efefef, solid);
// @include background-color(#00f);
ul {
@include rect(100%, 100%);
li{
@include rect(100%, 0.36rem);
@include border(0 0 1px, #efefef, solid);
@include line-height(0.36rem);
@include text-align();
&.active {
@include color(#f66);
}
}
}
}
.right {
@include flex();
@include rect(auto, 100%);
// @include background-color(#0f0);
@include overflow();
.top {
@include rect(100%, auto);
ul {
li {
@include rect(50%, 0.3rem);
@include overflow(hidden);
@include line-height(0.3rem);
@include text-align();
@include display(inline-block);
img {
@include rect(100%, auto);
}
&.active {
@include border(1px, #f66, solid);
}
}
}
}
}
}
}
</style>
import axios from '@/utils/request'

export default {
namespaced: true,
state: {
kindlist: [],
brandlist: [],
prolist: []
},
actions: {
getKindlist (context) {
let url = '/pro/type?type=type'
return new Promise(resolve => {
axios.get(url).then(res => {
console.log('kind', res.data)
if (res.data.code === '10119') {
// this.$router.push('/login')
resolve(0)
} else {
// this.kindlist = res.data.data
// this.getBrand(this.kindlist[0], 0)
context.commit({
type: 'changeKindlist',
data: res.data.data
})
resolve(1)
}
})
})
},
getBrandlist (context, data) {
let url = '/pro/category?type=' + data.item
return new Promise(resolve => {
axios.get(url).then((res) => {
console.log(res.data)
if (res.data.code === '10119') {
resolve(0)
} else {
// this.brandlist = res.data.data
// this.getlist(this.brandlist[0], 0)
context.commit({
type: 'changeBrandlist',
data: res.data.data
})
resolve(1)
}
})
})
},
getProlist (context, data) {
let url = '/pro/brandcategory?brand=' + data.brand
return new Promise(resolve => {
axios.get(url).then((res) => {
console.log(res.data)
if (res.data.code === '10119') {
resolve(0)
} else {
context.commit({
type: 'changeProlist',
data: res.data.data
})
resolve(1)
}
})
})
}
},
mutations: {
changeKindlist (state, data) {
state.kindlist = data.data
},
changeBrandlist (state, data) {
state.brandlist = data.data
},
changeProlist (state, data) {
state.prolist = data.data
}
}
}

mapState, mapActions的更多相关文章

  1. 理解Vuex的辅助函数mapState, mapActions, mapMutations用法

    在讲解这些属性之前,假如我们项目的目录的结构如下: ### 目录结构如下: demo1 # 工程名 | |--- dist # 打包后生成的目录文件 | |--- node_modules # 所有的 ...

  2. [转]理解Vuex的辅助函数mapState, mapActions, mapMutations用法

    原文地址:https://www.cnblogs.com/tugenhua0707/p/9794423.html 在讲解这些属性之前,假如我们项目的目录的结构如下: ### 目录结构如下: demo1 ...

  3. Vuex中mapState的用法

    Vuex中mapState的用法   今天使用Vuex的时候遇到一个坑,也可以说是自己的无知吧,折腾了好久,终于发现自己代码的错误了.真是天雷滚滚~~~~~~ index.js import Vue ...

  4. Vue状态管理vuex

    前面的话 由于多个状态分散的跨越在许多组件和交互间各个角落,大型应用复杂度也经常逐渐增长.为了解决这个问题,Vue提供了vuex.本文将详细介绍Vue状态管理vuex 引入 当访问数据对象时,一个 V ...

  5. vue学习之vuex

    1  首先还是安装 npm install vuex --save. 2 在src这种创建目录为store 创建 index.js  (getters.js ,actions.js ,mutation ...

  6. 解决刷新页面vuex store中数据丢失的问题

    **问题背景:**页面刷新后,vuex中的数据丢失.这是因为:js代码是运行在内存中的,代码运行时的所有变量.函数也都是保存在内存中的.进行刷新页面的操作,以前申请的内存被释放,重新加载脚本代码,变量 ...

  7. vue+vuex 回退定位到初始位置

    先放出两张图(没错,你还在9012,做为一名资深设计师我唯一的技能点就是留白),简单说明下问题未做回退定位(从落地页回退,每次都回到A位置)想死啊有木有,每次都需要手动重新定位来选择,你大哥看到你做个 ...

  8. vuex2.0 基本使用(3) --- getter

    有的组件中获取到 store 中的state,  需要对进行加工才能使用,computed 属性中就需要写操作函数,如果有多个组件中都需要进行这个操作,那么在各个组件中都写相同的函数,那就非常麻烦,这 ...

  9. 使用vue iview遇到的一些问题

    使用阿里巴巴图标库 下载代码 这五个文件 iconfount.css 如果导入多个文件记得把@font-face复制到里面 改成./路径 //main.js import './assets/font ...

  10. vuex-Module

    Vuex 允许将 store 分割成模块(module). 每个模块拥有自己的 state.mutation.action.getter.甚至是嵌套子模块 const moduleA = { stat ...

随机推荐

  1. JavaSSM

    Day1221 一.IT行业分类 前端 用户界面,眼睛能看到的,视觉效果比较. html5.css和css3.javascript.jquery.技术基础 bootstrap(css框架).vue.j ...

  2. SQL Server 错误:特殊符号“•”导致的sql查询问题

    问题描述: 对于一些标题或字符串,例如: 如果导入数据库,就会发现会自动变成?号了: 在进行SQL查询的时候,会出现一个同一条sql语句在mysql直接执行sql可以查询到,但是mssql进行查询的时 ...

  3. Git本地仓库的文件夹不显示红色感叹号、绿色对号等图标

    参考 https://blog.csdn.net/Elon15/article/details/125898375 主要是  在文件名前加8个空格(最少8个)!!!!

  4. vue-设置页面滚动高度不生效问题处理

    首先,我遇到的问题是 无法保留(B)页面滚动的位置(scrollTop ) 无法赋值?! 黄色框是滚动部分(非最外层) 参考:https://www.csdn.net/tags/OtDakg2sOTA ...

  5. ddddd

    项目二阶段总结 账户微服务 短信发送 1.压测发现问题 首先对短信smscomponent的send方法在test单元测试类中测试,不是真的发短信测试,可以建立请求开始和结束的时间戳来确定请求的耗时. ...

  6. JSP第五周作业

    1.教材p39实验3(听英语) <%@ page language="java" import="java.util.*" pageEncoding=&q ...

  7. SQLServer数据库执行时间

    with kk AS( SELECT TOP 2000 total_worker_time/1000 AS [总消耗CPU 时间(ms)],execution_count [运行次数], qs.tot ...

  8. LoadRunner压力测试(web)

    1.打开Virtual User Generator->新建脚本->选择创建新脚本类型,web-HTTP,HTML->创建 2.录制脚本 3.停止脚本录制 4.创建controlle ...

  9. SpringBoot多数据源yaml配置

    1.配置多数据源 pom文件 <dependency> <groupId>com.baomidou</groupId> <artifactId>dyna ...

  10. Kafka源码阅读系列——Producer

    Producer Kafka源码的exmaple模块有一个Producer类,继承了Thread类,构造方法会指定topic,是否异步,是否幂等,配置Kafka集群信息,初始化一个KafkaProdu ...