ã¬ã¤ã
åºæ¬çãªä½¿ãæ¹
- ã¤ã³ã¹ãã¼ã«
- ã¯ããã«
- Vue ã¤ã³ã¹ã¿ã³ã¹
- ãã³ãã¬ã¼ãæ§æ
- ç®åºããããã£ã¨ã¦ã©ããã£
- ã¯ã©ã¹ã¨ã¹ã¿ã¤ã«ã®ãã¤ã³ãã£ã³ã°
- æ¡ä»¶ä»ãã¬ã³ããªã³ã°
- ãªã¹ãã¬ã³ããªã³ã°
- ã¤ãã³ããã³ããªã³ã°
- ãã©ã¼ã å ¥åãã¤ã³ãã£ã³ã°
- ã³ã³ãã¼ãã³ãã®åºæ¬
ã³ã³ãã¼ãã³ãã®è©³ç´°
- ã³ã³ãã¼ãã³ãã®ç»é²
- ããããã£
- ã«ã¹ã¿ã ã¤ãã³ã
- ã¹ããã
- åç & éåæã³ã³ãã¼ãã³ã
- ç¹å¥ãªåé¡ã«å¯¾å¦ãã
ãã©ã³ã¸ã·ã§ã³ã¨ã¢ãã¡ã¼ã·ã§ã³
- Enter/Leave ã¨ãã©ã³ã¸ã·ã§ã³ä¸è¦§
- ç¶æ ã®ãã©ã³ã¸ã·ã§ã³
åå©ç¨ã¨æ§æ
- ããã¯ã¹ã¤ã³
- ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ã
- æç»é¢æ°ã¨JSX
- ãã©ã°ã¤ã³
- ãã£ã«ã¿ã¼
ãã¼ã«
- åä¸ãã¡ã¤ã«ã³ã³ãã¼ãã³ã
- ãã¹ã
- TypeScript ã®ãµãã¼ã
- ãããã¯ã·ã§ã³ç°å¢ã¸ã®é ä¿¡
ã¹ã±ã¼ã«ã¢ãã
- ã«ã¼ãã£ã³ã°
- ç¶æ 管ç
- ãµã¼ããµã¤ãã¬ã³ããªã³ã°
- ã»ãã¥ãªãã£
å é¨
- ãªã¢ã¯ãã£ãã®æ¢æ±
移è¡
- Vue 1.x ããã®ç§»è¡
- Vue Router 0.7.x ããã®ç§»è¡
- Vuex 0.6.x ãã 1.0 ã¸ã®ç§»è¡
ãã®ä»
- ä»ã®ãã¬ã¼ã ã¯ã¼ã¯ã¨ã®æ¯è¼
- Vue.js ã³ãã¥ããã£ã¸åå ãã¾ããã!
- ãã¼ã ã«ä¼ãã
v2.x 以åã®ããã¥ã¡ã³ãã§ãã v3.x ã®ããã¥ã¡ã³ããè¦ããå ´åã¯ãã¡ã
Vue ã¤ã³ã¹ã¿ã³ã¹
æçµæ´æ°æ¥: 2020å¹´9æ7æ¥
Vue ã¤ã³ã¹ã¿ã³ã¹ã®ä½æ
å
¨ã¦ã® Vue ã¢ããªã±ã¼ã·ã§ã³ ã¯ãVue
é¢æ°ã§æ°ãã Vue ã¤ã³ã¹ã¿ã³ã¹ãä½æãããã¨ã«ãã£ã¦èµ·åããã¾ãã
var vm = new Vue({
// ãªãã·ã§ã³
})
Vue ã®ãã¶ã¤ã³ã¯ãMVVM ãã¿ã¼ã³ã¨å³å¯ã«ã¯é¢é£ãç¡ããã®ã®ãé¨åçã«ã¯å½±é¿ãåãã¦ãã¾ããæ
£ä¾ã¨ãã¦ã vm
(ViewModel ã®ç¥) ã Vue ã¤ã³ã¹ã¿ã³ã¹ã®å¤æ°åã¨ãã¦ãã使ãã¾ãã
Vue ã¤ã³ã¹ã¿ã³ã¹ãçæããã«ã¯ããªãã·ã§ã³ãªãã¸ã§ã¯ãã渡ãã¾ãããã®ã¬ã¤ãã®å¤§é¨åã§ã¯ããããã®ãªãã·ã§ã³ã使ç¨ãã¦æãã æåã«ããããã®æ¹æ³ã«ã¤ãã¦èª¬æãã¦ãã¾ããåèã¾ã§ã«ãå ¨ã¦ã®ãªãã·ã§ã³ã®ä¸è¦§ã¯API ãªãã¡ã¬ã³ã¹ã§åç §ã§ãã¾ãã
Vue ã¢ããªã±ã¼ã·ã§ã³ã¯ã new Vue
ã§ä½æãããã«ã¼ã Vue ã¤ã³ã¹ã¿ã³ã¹(root Vue instance)ã§æ§æãããå¿
è¦ã«å¿ãã¦ãã¹ããããããªã¼ãåå©ç¨å¯è½ãªã³ã³ãã¼ãã³ãã§å½¢æããã¾ããä¾ãã°ãTodo ã¢ããªã®ã³ã³ãã¼ãã³ãããªã¼ã¯æ¬¡ã®ããã«ãªãã¾ãã
Root Instance
ââ TodoList
ââ TodoItem
â ââ TodoButtonDelete
â ââ TodoButtonEdit
ââ TodoListFooter
ââ TodosButtonClear
ââ TodoListStatistics
ã³ã³ãã¼ãã³ãã·ã¹ãã ã«ã¤ãã¦ã¯å¾ã»ã©è©³ç´°ã説æãã¾ããä»ã¯ãå ¨ã¦ã® Vue ã³ã³ãã¼ãã³ã㯠Vue ã¤ã³ã¹ã¿ã³ã¹ã§ãåããªãã·ã§ã³ãªãã¸ã§ã¯ããåãå ¥ãã(ããã¤ãã®ã«ã¼ãç¹æã®ãªãã·ã§ã³ãé¤ã)ã¨ç解ãã¦ããã°ååã§ãã
ãã¼ã¿ã¨ã¡ã½ãã
Vue ã¤ã³ã¹ã¿ã³ã¹ãä½æãããã¨ãèªèº«ã® data
ãªãã¸ã§ã¯ãã®å
¨ã¦ã®ããããã£ããªã¢ã¯ãã£ãã·ã¹ãã ã«è¿½å ãã¾ãããããã®ããããã£ã®å¤ãå¤æ´ããã¨ããã¥ã¼ãâåå¿âããæ°ããå¤ã«ä¸è´ããããã«æ´æ°ãã¾ãã
// ãã¼ã¿ãªãã¸ã§ã¯ã
var data = { a: 1 }
// Vue ã¤ã³ã¹ã¿ã³ã¹ã«ãªãã¸ã§ã¯ãã追å ãã
var vm = new Vue({
data: data
})
// ã¤ã³ã¹ã¿ã³ã¹ã®ããããã£ãåå¾ããã¨ã
// å
ã®ãã¼ã¿ãããã®ããããã£ãè¿ããã¾ã
vm.a == data.a // => true
// ããããã£ã¸ã®ä»£å
¥ã¯ãå
ã®ãã¼ã¿ã«ãåæ ããã¾ã
vm.a = 2
data.a // => 2
// ... ããã¦ããã®éãã¾ããããã§ã
data.a = 3
vm.a // => 3
ãã®ãã¼ã¿ãå¤æ´ããã¨ããã¥ã¼ãåã¬ã³ããªã³ã°ããã¾ããdata
ã®ããããã£ã¯ãã¤ã³ã¹ã¿ã³ã¹ãä½æãããã¨ãã«åå¨ãã¦ããå ´åã«ã®ã¿ãªã¢ã¯ãã£ãã§ãã ã¤ã¾ãã以ä¸ã®ããã«æ°ããããããã£ã追å ããå ´åã
vm.b = 'hi'
ãã®å¾ã b
ã¸ã®å¤æ´ã¯ãã¥ã¼ã®æ´æ°ãå¼ãèµ·ãããªãã§ãããã å¾ã§ããããã£ãå¿
è¦ã«ãªããã¨ãããã£ã¦ãããªãã°ã空ã§ãåå¨ããªãå ´åã§ãåæå¤ãè¨å®ããã ãã§æ¸ã¿ã¾ãã ä¾ï¼
data: {
newTodoText: '',
visitCount: 0,
hideCompletedTodos: false,
todos: [],
error: null
}
ããã«å¯¾ããå¯ä¸ã®ä¾å¤ã¯ãæ¢åã®ããããã£ã®å¤æ´ãé²ã Object.freezeï¼ï¼
ã®ä½¿ç¨ã§ããããã¯ãªã¢ã¯ãã£ãã·ã¹ãã ãå¤æ´ã 追跡 ãããã¨ãã§ããªããã¨ãæå³ãã¾ãã
var obj = {
foo: 'bar'
}
Object.freeze(obj)
new Vue({
el: '#app',
data: obj
})
<div id="app">
<p>{{ foo }}</p>
<!-- ãã㯠`foo` ãæ´æ°ããªããªãã¾ã! -->
<button v-on:click="foo = 'baz'">Change it</button>
</div>
data ããããã£ã«å ãã¦ãVue ã¤ã³ã¹ã¿ã³ã¹ã¯ãããã¤ãã®ä¾¿å©ãªããããã£ã¨ã¡ã½ãããæã£ã¦ãã¾ãããããã¯ã¦ã¼ã¶å®ç¾©ã®ããããã£ã¨åºå¥ããããã«ãé ã« $
ãä»ãããã¦ãã¾ãã ä¾ï¼
var data = { a: 1 }
var vm = new Vue({
el: '#example',
data: data
})
vm.$data === data // => true
vm.$el === document.getElementById('example') // => true
// $watch ã¯ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããã§ã
vm.$watch('a', function (newValue, oldValue) {
// ãã®ã³ã¼ã«ããã¯ã¯ `vm.a` ã®å¤ãå¤ããæã«å¼ã°ãã¾ã
})
å°æ¥çã«ã¯ãã¤ã³ã¹ã¿ã³ã¹ã®ããããã£ã¨ã¡ã½ããã®å®å ¨ãªãªã¹ãã«ã¤ãã¦ã¯ã API ãªãã¡ã¬ã³ã¹ ãåç §ãã¦ãã ããã
ã¤ã³ã¹ã¿ã³ã¹ã©ã¤ããµã¤ã¯ã«ããã¯
å Vue ã¤ã³ã¹ã¿ã³ã¹ã¯ãçææã«ä¸é£ã®åæåãè¡ãã¾ããä¾ãã°ããã¼ã¿ã®ç£è¦ã®ã»ããã¢ããããã³ãã¬ã¼ãã®ã³ã³ãã¤ã«ãDOM ã¸ã®ã¤ã³ã¹ã¿ã³ã¹ã®ãã¦ã³ãããã¼ã¿ãå¤åããã¨ãã® DOM ã®æ´æ°ãªã©ãããã¾ãããã®åæåã®éç¨ã§ãç¹å®ã®æ®µéã§ã¦ã¼ã¶ã¼èªèº«ã®ã³ã¼ãã追å ãããããã¤ãã® ã©ã¤ããµã¤ã¯ã«ããã¯(lifecycle hooks) ã¨å¼ã°ããé¢æ°ãå®è¡ãã¾ãã
ä¾ãã°ãcreated
ããã¯ã¯ã¤ã³ã¹ã¿ã³ã¹ãçæãããå¾ã«ã³ã¼ããå®è¡ãããã¨ãã«ä½¿ããã¾ãã
new Vue({
data: {
a: 1
},
created: function () {
// `this` 㯠vm ã¤ã³ã¹ã¿ã³ã¹ãæãã¾ã
console.log('a is: ' + this.a)
}
})
// => "a is: 1"
ãã®ä»ã«ãã¤ã³ã¹ã¿ã³ã¹ã®ã©ã¤ããµã¤ã¯ã«ã®æ§ã
ãªæ®µéã§å¼ã°ããããã¯ãããã¾ããä¾ãã°ãmounted
ã updated
ããã㦠destroyed
ãªã©ãããã¾ããå
¨ã¦ã®ã©ã¤ããµã¤ã¯ã«ããã¯ã¯ãthis
ã Vue ã¤ã³ã¹ã¿ã³ã¹ãæãå½¢ã§å®è¡ããã¾ãã
ã¤ã³ã¹ã¿ã³ã¹ããããã£ã¾ãã¯ã³ã¼ã«ããã¯ã§ã¢ãã¼é¢æ° ã使ç¨ããªãã§ãã ãããä¾ãã°ã created: () => console.log(this.a)
ã vm.$watch('a', newValue => this.myMethod())
ã§ããã¢ãã¼é¢æ°ã¯ this
ããããªããããthis
ã¯ä»ã®å¤æ°ã¨åæ§ã«è¦ã¤ããã¾ã§è¦ªã¹ã³ã¼ããã¬ãã·ã«ã«ã«æ¢ç´¢ãããããã¦ãã°ãã°ãUncaught TypeError: Cannot read property of undefined
ã¾ã㯠Uncaught TypeError: this.myMethod is not a function
ã®ãããªã¨ã©ã¼ãçºçãã¾ãã
ã©ã¤ããµã¤ã¯ã«ãã¤ã¢ã°ã©ã
以ä¸ã¯ãã¤ã³ã¹ã¿ã³ã¹ã©ã¤ããµã¤ã¯ã«ã®ãã¤ã¢ã°ã©ã ã§ãã
ä»ã¯ãã®ãã¤ã¢ã°ã©ã ãå®å
¨ã«ç解ããå¿
è¦ã¯ããã¾ããããå°æ¥å½¹ã«ç«ã¤ãã¨ã§ãããã