Full-Stack Web Development with Vue.js and Node

(singke) #1
Introducing Vuex Chapter 8

methods: mapActions([
'increment',
'decrement'
])
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

To invoke these actions, let's create two buttons. In HelloWorld.vue, let's add the


following lines of code:


<template>
<div class="hello">
<h1>The count is: {{ fetchCount }}</h1>
<button class="btn btn-primary" @click="increment">Increase</button>
<button class="btn btn-primary" @click="decrement">Decrease</button>
</div>
</template>
...

The preceding lines of code add two buttons, which, when clicked, call a method to


increment or decrement the count. Let's also import Bootstrap for CSS. In index.html, add


the following code:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
" integrity="sha384-
BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<title>vuex-tutorial</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Free download pdf