欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2021年06月24日 15:25:27   作者:SikiChan  
這篇文章主要為大家詳細(xì)介紹了vuex實(shí)現(xiàn)一個(gè)簡易計(jì)數(shù)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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í)閱讀。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vant的picker組件設(shè)置文字超長滾動(dòng)方式

    vant的picker組件設(shè)置文字超長滾動(dòng)方式

    這篇文章主要介紹了vant的picker組件設(shè)置文字超長滾動(dòng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 解決Vue keep-alive 調(diào)用 $destory() 頁面不再被緩存的情況

    解決Vue keep-alive 調(diào)用 $destory() 頁面不再被緩存的情況

    這篇文章主要介紹了解決Vue keep-alive 調(diào)用 $destory() 頁面不再被緩存的情況,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • vue項(xiàng)目中使用vue-layer彈框插件的方法

    vue項(xiàng)目中使用vue-layer彈框插件的方法

    這篇文章主要介紹了vue項(xiàng)目中使用vue-layer彈框插件的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • vue中的自定義指令clickOutside

    vue中的自定義指令clickOutside

    這篇文章主要介紹了vue中的自定義指令clickOutside,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Vue.js前端框架之事件處理小結(jié)

    Vue.js前端框架之事件處理小結(jié)

    這篇文章主要介紹了Vue.js前端框架之事件處理小結(jié),本文給大家介紹了v-on 指令的基本用法,通過實(shí)例講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能

    vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能

    這篇文章主要介紹了vue點(diǎn)擊按鈕動(dòng)態(tài)創(chuàng)建與刪除組件功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • vue自定義插件封裝,實(shí)現(xiàn)簡易的elementUi的Message和MessageBox的示例

    vue自定義插件封裝,實(shí)現(xiàn)簡易的elementUi的Message和MessageBox的示例

    這篇文章主要介紹了vue自定義插件封裝,實(shí)現(xiàn)簡易的elementUi的Message和MessageBox的示例,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2020-11-11
  • Vue props實(shí)現(xiàn)父組件給子組件傳遞數(shù)據(jù)的方式

    Vue props實(shí)現(xiàn)父組件給子組件傳遞數(shù)據(jù)的方式

    Vue中的配置項(xiàng)Props能讓組件接收外部傳遞過來的數(shù)據(jù),本文給大家介紹了Vue props實(shí)現(xiàn)父組件給子組件傳遞數(shù)據(jù)的幾種方式,文中有詳細(xì)的實(shí)現(xiàn)方式,具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-10-10
  • vue中keep-alive,include的緩存問題

    vue中keep-alive,include的緩存問題

    這篇文章主要介紹了vue中keep-alive,include的緩存問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Vue.js如何獲取data-*的值

    Vue.js如何獲取data-*的值

    這篇文章主要介紹了Vue.js如何獲取data-*的值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09

最新評(píng)論