国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

vuex實(shí)現(xiàn)簡(jiǎn)易計(jì)數(shù)器

2019-11-20 08:38:52
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了vue.js計(jì)數(shù)器的制作方法,供大家參考,具體內(nèi)容如下

src/components

Hello.vue

<template> <div class="hello"> <h1>Now count is {{counterValue}}</h1> <br> </div></template><script>import { getCount } from '../vuex/getters'export default { vuex: { getters: {  counterValue: getCount } }, data () { return { } }}</script><style scoped>h1 { color: #42b983;}</style>

Increate.vue

<template> <div> <button @click='increment' class="btn btn-success">click me + 3</button> <button @click='reduce' class="btn btn-warning">click me - 1</button> </div></template><script>import { incrementCounter, reduceCounter } from '../vuex/action'export default { vuex: { actions: {  increment: incrementCounter,  reduce: reduceCounter } }, data: function () { return { } }, computed: {}, ready: function () {}, attached: function () {}, methods: {}, components: {}}</script><style lang="css"></style>

src/vuex

store.js

import Vue from 'vue'import Vuex from 'Vuex'Vue.use(Vuex)const state = { count: 0}const mutations = { INCREMENT (state, n) { state.count = state.count + n }, REDUCE (state) { state.count-- }}export default new Vuex.Store({ state, mutations})

action.js

export const incrementCounter = ({dispatch}) => dispatch('INCREMENT', 3)export const reduceCounter = ({dispatch}) => dispatch('REDUCE')

getters.js

export function getCount (state) { return state.count}

src/App.vue

<template> <div id="app"> <img class="logo" src="./assets/logo.png"> <hello></hello> <increate></increate> </div></template><script>import Hello from './components/Hello'import Increate from './components/Increate'import store from './vuex/store'export default { store, components: { Hello, Increate }}</script><style>html { height: 100%;}body { display: flex; align-items: center; justify-content: center; height: 100%;}#app { color: #2c3e50; margin-top: -100px; max-width: 600px; font-family: Source Sans Pro, Helvetica, sans-serif; text-align: center;}#app a { color: #42b983; text-decoration: none;}.logo { width: 100px; height: 100px}</style>

 src/main.js

// 入口文件import Vue from 'vue'import App from './App'import VueRouter from 'vue-router'import VueResource from 'vue-resource'/* eslint-disable import VueRouter from 'vue-router'no-new */new Vue({ el: 'body', components: { App }})Vue.use(VueRouter)Vue.use(VueResource)var router = new VueRouter({ hashbang: false, // 設(shè)置為true時(shí),所有的路徑都會(huì)被格式化為#!開頭 history: true // 默認(rèn)false,利用history.pushState(), history.replaceState()來管理瀏覽歷史記錄})// require('./routers')(router)router.start(App, '#app')

效果圖:

本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 延庆县| 阜南县| 桃园市| 惠东县| 甘孜县| 凤阳县| 镇平县| 龙泉市| 晋宁县| 卓尼县| 宝兴县| 长葛市| 天柱县| 安新县| 博野县| 武宣县| 利辛县| 久治县| 建水县| 阳谷县| 伊金霍洛旗| 湘潭市| 章丘市| 华阴市| 金塔县| 偏关县| 东港市| 行唐县| 萝北县| 海城市| 景谷| 囊谦县| 龙川县| 林州市| 合作市| 泰来县| 兴和县| 旌德县| 响水县| 瑞金市| 旌德县|