Commit 8ca925eb authored by huanglu's avatar huanglu

feat: init

parent 27abc9e2
......@@ -2,8 +2,6 @@ import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '@/views/home';
const Cart = () => import('@/views/cart');
Vue.use(VueRouter);
// 单入口路由配置
......@@ -13,15 +11,10 @@ const routes = [
name: 'Home',
component: Home
},
{
path: '/cart',
name: 'Cart',
component: Cart
}
];
const router = new VueRouter({
mode: 'hash',
mode: 'history',
base: process.env.BASE_URL,
routes
});
......
......@@ -11,63 +11,62 @@
* @param {any} val
*/
export function setStorage(key, val) {
localStorage.setItem(key, JSON.stringify(val))
}
/**
localStorage.setItem(key, JSON.stringify(val))
}
/**
* 获取本地缓存
* @param {string} key
*/
export function getStorage(key) {
const val = localStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val)
}
/**
export function getStorage(key) {
const val = localStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val)
}
/**
* 移除某一项缓存
* @param {string} key
*/
export function removeStorage(key) {
localStorage.removeItem(key)
}
/**
export function removeStorage(key) {
localStorage.removeItem(key)
}
/**
* 清除所有缓存
*/
export function clearStorage() {
localStorage.clear()
}
/**
export function clearStorage() {
localStorage.clear()
}
/**
* 设置本地临时缓存
* @param {string} key
* @param {any} val
*/
export function setSession(key, val) {
sessionStorage.setItem(key, JSON.stringify(val))
}
/**
export function setSession(key, val) {
sessionStorage.setItem(key, JSON.stringify(val))
}
/**
* 获取本地临时缓存
* @param {string} key
*/
export function getSession(key) {
const val = sessionStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val)
}
/**
export function getSession(key) {
const val = sessionStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val)
}
/**
* 移除某一项临时缓存
* @param {string} key
*/
export function removeSession(key) {
sessionStorage.removeItem(key)
}
/**
export function removeSession(key) {
sessionStorage.removeItem(key)
}
/**
* 清除所有临时缓存
*/
export function clearSession() {
sessionStorage.clear()
}
\ No newline at end of file
export function clearSession() {
sessionStorage.clear()
}
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<template>
<div class='cartpage'>
<h1 v-for="item in carts" :key="item.id">
{{ JSON.stringify(item) }}
</h1>
<div>
<button @click="addCartInpage">add</button>
<button @click="deleteOne">deleteOne</button>
<button @click="deleteCartInpage">deleteAll</button>
</div>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
export default {
name: 'cart',
// import引入的组件需要注入到对象中才能使用
components: {
},
data() {
// 这里存放数据
return {
};
},
computed: {
...mapState({
carts: (state) => state.cart.carts,
}),
},
watch: {},
methods: {
...mapActions(['cart/addCart', 'cart/deleteAll', 'cart/deleteCart']),
addCartInpage() {
if (!this.addIndex) this.addIndex = 1;
this['cart/addCart']({ id: this.addIndex, cart: 'sfshfksfhs' });
this.addIndex += 1;
},
deleteCartInpage() {
if (!this.deleteIndex) {
this.deleteIndex = 1;
}
this['cart/deleteAll'](this.deleteIndex);
this.deleteIndex += 1;
},
deleteOne() {
}
},
created() {
},
mounted() {
},
};
</script>
<style lang='scss' scoped>
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment