packtpublishing / learning-vuejs-2 Goto Github PK
View Code? Open in Web Editor NEWThis is the code repository for Learning Vue.js 2, published by Packt.
License: MIT License
This is the code repository for Learning Vue.js 2, published by Packt.
License: MIT License
Just a note to anyone following the book, Chapter 5.
According to this file :
Learning-Vuejs-2/chapter5/pomodoro/package.json
This sample is using Vue JS v1, and already has the components and vuex stuff (I assume specific for that version). There are also some differences in how the getters are defined for CountdownComponent.vue based in the book.
Code sample
import { getMinutes, getSeconds } from '../vuex/getters'
export default {
vuex: {
getters: {
min: getMinutes,
sec: getSeconds
}
}
}
Book
import { mapGetters } from 'vuex'
export default {
computed: mapGetters({
min: 'getMinutes',
sec: 'getSeconds'
})
}
As a result, students cannot follow through (from scratch) with the chapter's exercise if taking the source code from Learning-Vuejs-2/chapter5/pomodoro.
Just to highlight that the chapter6/pomodoro had jade templates and is using VueJS v1, not really a good starting point for plugin development.
Can you kindly help us out and let us have a good starting point to continue the chapter please thank you.
mutations.js --> "Stop button" in this sample should have this line added
clearInterval(state.interval)
Currently clicking on this button doesn't stop the timer.
Let's create a simple actions file for our change, message example. But before that, let's create one more item for the store's initial state, counter, and initialize it with a "0" value. So, our store will look like the following:
//store.js
import Vue from 'vue'
import Vuex from 'vuex'
import { CHANGE_MSG, INCREMENT_COUNTER } from './mutation_types'
Vue.use(Vuex)
const state = {
message: 'Hello Vue!',
counter: 0
}
const mutations = {
[CHANGE_MSG](state, msg) {
state.message = msg
},
[INCREMENT_COUNTER](state) {
state.counter ++;
}
}
export default new Vuex.Store({
state,
mutations
})
Actually it should be as follow, the code hosts on Github.com is correct.
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters' //should add
import actions from './actions' //shoud add
import { CHANGE_MSG, INCREMENT_COUNTER } from './mutation_types'
Vue.use(Vuex)
const state = {
msg: 'Hello Vue!',
counter: 0
}
const mutations = {
[CHANGE_MSG](state, msg) {
state.msg = msg
},
[INCREMENT_COUNTER](state) {
state.counter ++
}
}
export default new Vuex.Store({
state, mutations, getters, actions//should add getters and actions.
})
In the book, there is a part where we should add a script entry to the package.json file so that we can easily start our server.
What worked for me was
"scripts": {
"dev": "node build/dev-server.js",
"server": "json-server --watch server/db.json",
<...>
}
Windows machines don't have cURL built in, so I would recommend using POSTMAN instead to test whether json-server is working properly after doing 'npm run server'.
https://github.com/PacktPublishing/Learning-Vuejs-2/blob/master/chapter6/shopping-list2/package.json
[error] "server": "node_modules/json-server/bin/index.js --watch server/db.json",
[fix] "server": "node node_modules/json-server/bin/index.js --watch server/db.json",
The unit tests for createShoppingList
& deleteShoppingList
from actions.js
in chapter 7 are missing from this repository. It's not exactly clear how to test these methods. Please add the tests or explain how to go about testing them here. As well, please go into further detail about the syntax in the method.
createShoppingList: (store, shoppinglist) => {
return api.addNewShoppingList(shoppinglist).then(() => {
store.dispatch('populateShoppingLists')
}, () => {
store.commit(types.ADD_SHOPPING_LIST, shoppinglist)
})
}
I don't understand why are there two objects and one being call like () => {...}
In the text, the steps say to do the following:
In step 4, the functionality works fine without binding the value to input and declaring any props:
<...>
<input @input = "onInput"/>
<...>
So why do we need to bind value to input inside the ChangeTitleComponent component's template and declare props if we are not receiving and value props inside the component in ShoppingListComponent?
// ShoppingListComponent
<
// ChangeTitleComponent
<input :value = "value" @input ="onInput"/>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.