{
"name": "vuejs2",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^2.6.14",
"vue-router": "3.6.5",
"vuex": "2.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"vue-template-compiler": "^2.6.14"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
<template>
<div>
{{ $store.state.result }}
</div>
</template>
<script>
export default {
name: 'AppCount'
}
</script>
<template>
<div>
<button @click="increment">Increment</button>
<button @click="decrement">Decrement</button>
</div>
</template>
<script>
export default {
name: 'AppCount',
methods: {
increment() {
this.$store.state.result++
},
decrement() {
this.$store.state.result--
}
}
}
</script>
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export const store = new Vuex.Store({
state: {
result: 0
}
})
import Vue from 'vue'
import App from './App.vue'
import {store} from './store.js'
Vue.config.productionTip = false
new Vue({
store,
render: h => h(App),
}).$mount('#app')
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<AppResult />
<br/>
<app-count />
</div>
</template>
<script>
import AppCount from './components/AppCount.vue'
import AppResult from './components/AppResult.vue'
export default {
name: 'App',
components: {
AppResult,
AppCount
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>