Commit 8ca925eb authored by huanglu's avatar huanglu

feat: init

parent 27abc9e2
...@@ -2,8 +2,6 @@ import Vue from 'vue'; ...@@ -2,8 +2,6 @@ import Vue from 'vue';
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';
import Home from '@/views/home'; import Home from '@/views/home';
const Cart = () => import('@/views/cart');
Vue.use(VueRouter); Vue.use(VueRouter);
// 单入口路由配置 // 单入口路由配置
...@@ -13,15 +11,10 @@ const routes = [ ...@@ -13,15 +11,10 @@ const routes = [
name: 'Home', name: 'Home',
component: Home component: Home
}, },
{
path: '/cart',
name: 'Cart',
component: Cart
}
]; ];
const router = new VueRouter({ const router = new VueRouter({
mode: 'hash', mode: 'history',
base: process.env.BASE_URL, base: process.env.BASE_URL,
routes routes
}); });
......
...@@ -12,62 +12,61 @@ ...@@ -12,62 +12,61 @@
*/ */
export function setStorage(key, val) { export function setStorage(key, val) {
localStorage.setItem(key, JSON.stringify(val)) localStorage.setItem(key, JSON.stringify(val))
} }
/** /**
* 获取本地缓存 * 获取本地缓存
* @param {string} key * @param {string} key
*/ */
export function getStorage(key) { export function getStorage(key) {
const val = localStorage.getItem(key) const val = localStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val) return val === 'undefined' ? '' : JSON.parse(val)
} }
/** /**
* 移除某一项缓存 * 移除某一项缓存
* @param {string} key * @param {string} key
*/ */
export function removeStorage(key) { export function removeStorage(key) {
localStorage.removeItem(key) localStorage.removeItem(key)
} }
/** /**
* 清除所有缓存 * 清除所有缓存
*/ */
export function clearStorage() { export function clearStorage() {
localStorage.clear() localStorage.clear()
} }
/** /**
* 设置本地临时缓存 * 设置本地临时缓存
* @param {string} key * @param {string} key
* @param {any} val * @param {any} val
*/ */
export function setSession(key, val) { export function setSession(key, val) {
sessionStorage.setItem(key, JSON.stringify(val)) sessionStorage.setItem(key, JSON.stringify(val))
} }
/** /**
* 获取本地临时缓存 * 获取本地临时缓存
* @param {string} key * @param {string} key
*/ */
export function getSession(key) { export function getSession(key) {
const val = sessionStorage.getItem(key) const val = sessionStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val) return val === 'undefined' ? '' : JSON.parse(val)
} }
/** /**
* 移除某一项临时缓存 * 移除某一项临时缓存
* @param {string} key * @param {string} key
*/ */
export function removeSession(key) { export function removeSession(key) {
sessionStorage.removeItem(key) sessionStorage.removeItem(key)
} }
/** /**
* 清除所有临时缓存 * 清除所有临时缓存
*/ */
export function clearSession() { export function clearSession() {
sessionStorage.clear() sessionStorage.clear()
} }
\ No newline at end of file
<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