ã¬ã¤ã
åºæ¬çãªä½¿ãæ¹
- ã¤ã³ã¹ãã¼ã«
- ã¯ããã«
- 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 ã®ããã¥ã¡ã³ããè¦ããå ´åã¯ãã¡ã
ãã©ã¼ã å ¥åãã¤ã³ãã£ã³ã°
æçµæ´æ°æ¥: 2020å¹´5æ15æ¥
åºæ¬çãªä½¿ãæ¹
form ã® input è¦ç´ ã textarea è¦ç´ ã select è¦ç´ ã«åæ¹å (two-way) ãã¼ã¿ãã¤ã³ãã£ã³ã°ãä½æããã«ã¯ãv-model
ãã£ã¬ã¯ãã£ãã使ç¨ãããã¨ãã§ãã¾ããããã¯ãèªåçã«å
¥åè¦ç´ ã®ã¿ã¤ãã«åºã¥ãã¦è¦ç´ ãæ´æ°ããããã®æ£ããæ¹æ³ãé¸æãã¾ããã¡ãã£ã¨éæ³ã®ããã§ãããv-model
ã¯ã¦ã¼ã¶ã¼ã®å
¥åã¤ãã³ãã«ããã¦ãã¼ã¿ãæ´æ°ããããã®åºæ¬çãªç³è¡£æ§æ (syntax sugar) ã§ãããã«å ãã¦ãããã¤ãã®ã¨ãã¸ã±ã¼ã¹ã«å¯¾ãã¦ã¯ç¹å¥ãªé
æ
®ããã¦ããã¾ãã
v-model
ã¯ä»»æã® form è¦ç´ ã«ãã value
ãchecked
ãã¾ã㯠selected
å±æ§ã®åæå¤ãç¡è¦ãã¾ããinput ã¾ã㯠textarea ã¯å¸¸ã«ãä¿¡é ¼ã§ããæ
å ±æºã¨ã㦠Vue ã¤ã³ã¹ã¿ã³ã¹ãæ±ãã¾ããã³ã³ãã¼ãã³ãã® data
ãªãã·ã§ã³ã®ä¸ã§ JavaScript å´ã§åæå¤ã宣è¨ããå¿
è¦ãããã¾ãã
v-model
ã¯ãå
é¨çã«ã¯ input è¦ç´ ã«å¿ãã¦ç°ãªãããããã£ã使ç¨ããç°ãªãã¤ãã³ããéåºãã¾ã:
- ããã¹ãã¨è¤æ°è¡ããã¹ãã¯ã
value
ããããã£ã¨input
ã¤ãã³ãã使ç¨ãã¾ã - ãã§ãã¯ããã¯ã¹ã¨ã©ã¸ãªãã¿ã³ã¯ã
checked
ããããã£ã¨change
ã¤ãã³ãã使ç¨ãã¾ã - é¸æãã£ã¼ã«ãã¯ã
value
ããããã£ã¨change
ã¤ãã³ãã使ç¨ãã¾ã
IME (ä¸å½èªãæ¥æ¬èªãéå½èªããã®ä») ãå¿
é ãªè¨èªã«ããã¦ãv-model
ã§ã¯ IME ã§ããã¹ãã確å®ããã¾ã§ã¯æ´æ°ãããªããã¨ã«æ³¨æãã¦ãã ããããããã®æ´æ°ã«å¯¾ãã¦å¯¾å¿ãããå ´åã¯ãinput
ã¤ãã³ãã代ããã«ä½¿ç¨ãã¾ãã
ããã¹ã
<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>
Message is: {{ message }}
è¤æ°è¡ããã¹ã
<span>Multiline message is:</span>
<p style="white-space: pre-line;">{{ message }}</p>
<br>
<textarea v-model="message" placeholder="add multiple lines"></textarea>
{{ message }}
textarea ã¸ã®æ¿å
¥ (<textarea>{{text}}</textarea>
) ã¯åãã¾ããã代ããã«ãv-model
ã使ç¨ãã¦ãã ããã
ãã§ãã¯ããã¯ã¹
åä½ã®ãã§ãã¯ããã¯ã¹ã¯ã boolean å¤ã§ã:
<input type="checkbox" id="checkbox" v-model="checked">
<label for="checkbox">{{ checked }}</label>
è¤æ°ã®ãã§ãã¯ããã¯ã¹ã¯ãåãé åã«æç¸ãã¾ãã:
<input type="checkbox" id="jack" value="Jack" v-model="checkedNames">
<label for="jack">Jack</label>
<input type="checkbox" id="john" value="John" v-model="checkedNames">
<label for="john">John</label>
<input type="checkbox" id="mike" value="Mike" v-model="checkedNames">
<label for="mike">Mike</label>
<br>
<span>Checked names: {{ checkedNames }}</span>
new Vue({
el: '...',
data: {
checkedNames: []
}
})
Checked names: {{ checkedNames }}
ã©ã¸ãª
<input type="radio" id="one" value="One" v-model="picked">
<label for="one">One</label>
<br>
<input type="radio" id="two" value="Two" v-model="picked">
<label for="two">Two</label>
<br>
<span>Picked: {{ picked }}</span>
Picked: {{ picked }}
é¸æ
åä½ã®é¸æ:
<select v-model="selected">
<option disabled value="">Please select one</option>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<span>Selected: {{ selected }}</span>
new Vue({
el: '...',
data: {
selected: ''
}
})
v-model
ã®å¼ã®åæå¤ããªãã·ã§ã³ã®ã©ãã¨ãä¸è´ããªãå ´åã<select>
è¦ç´ 㯠âæªé¸æâ ã®ç¶æ
ã§æç»ããã¾ããiOS ã§ã¯ããã®å ´å iOS ã change
ã¤ãã³ããçºçãããªããããæåã®ã¢ã¤ãã ãé¸æã§ããªããªãã¾ãããããã£ã¦ãä¸è¨ã®ä¾ã«ç¤ºãããã«ãdisabled ãªç©ºã®å¤ã®ãªãã·ã§ã³ã追å ãã¦ãããã¨ããããããã¾ãã
è¤æ°ã®é¸æï¼é åã«æç¸ï¼:
<select v-model="selected" multiple>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<br>
<span>Selected: {{ selected }}</span>
Selected: {{ selected }}
åçãªãã·ã§ã³ã¯ v-for
ã§æç»ã§ãã¾ã:
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
new Vue({
el: '...',
data: {
selected: 'A',
options: [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
]
}
})
å¤ã®ãã¤ã³ãã£ã³ã°
radio ã checkbox ã select ãªãã·ã§ã³ã®ã v-model
ã§ãã¤ã³ãã£ã³ã°ãããå¤ã¯é常ã¯éçãªæåå (ãã§ãã¯ããã¯ã¹ãªã boolean) ã§ã:
<!-- ãã§ãã¯ãããã¨ãã`picked` ã¯æåå"a"ã«ãªãã¾ã -->
<input type="radio" v-model="picked" value="a">
<!-- `toggle` 㯠true ãã¾ã㯠false ã®ã©ã¡ããã§ã -->
<input type="checkbox" v-model="toggle">
<!-- æåã®ãªãã·ã§ã³ãé¸æãããã¨ãã`selected` ã¯æåå"abc"ã§ã -->
<select v-model="selected">
<option value="abc">ABC</option>
</select>
ããããæã«ã¯ãVue ã¤ã³ã¹ã¿ã³ã¹ã®åçãªããããã£ã«å¤ãæç¸ããããªãããããã¾ããããããéæããããã« v-bind
ã使ç¨ãããã¨ãã§ãã¾ãã å ãã¦ãv-bind
ã使ç¨ãããã¨ã§ input å¤ã«æåå以å¤ã®å¤ãæç¸ãããã¨ãã§ããããã«ãªãã¾ãã
ãã§ãã¯ããã¯ã¹
<input
type="checkbox"
v-model="toggle"
true-value="yes"
false-value="no"
>
// ãã§ãã¯ãããã¨ã:
vm.toggle === 'yes'
// ãã§ãã¯ãå¤ãããã¨ã:
vm.toggle === 'no'
true-value
㨠false-value
å±æ§ã¯å
¥åãã©ã¼ã ã® value
å±æ§ã«ã¯å½±é¿ãåã¼ãã¾ããããªããªããã©ã¦ã¶ã¯ãã©ã¼ã ã®éä¿¡ã®ä¸ã«ãã§ãã¯ããã¦ããªããã§ãã¯ããã¯ã¹ãå«ããªãããã§ãã 2ã¤ã®å¤ (ã¤ã¾ã âyesâ ã¾ã㯠ânoâ) ã®ã©ã¡ãããå¿
ããã©ã¼ã ã§éä¿¡ããããã¨ãä¿è¨¼ããã«ã¯ã代ããã«ã©ã¸ãªã使ç¨ãã¦ãã ããã
ã©ã¸ãª
<input type="radio" v-model="pick" v-bind:value="a">
// ãã§ãã¯ããã¨ã:
vm.pick === vm.a
é¸æãªãã·ã§ã³
<select v-model="selected">
<!-- ã¤ã³ã©ã¤ã³ãªãã¸ã§ã¯ããªãã©ã« -->
<option v-bind:value="{ number: 123 }">123</option>
</select>
// é¸æããã¨ã:
typeof vm.selected // => 'object'
vm.selected.number // => 123
修飾å
.lazy
ããã©ã«ãã§ã¯ã v-model
ã¯å input
ã¤ãã³ã (ä¸è¨ã® IME 確å®åãé¤ãã¦) å¾ã«ããã¼ã¿ã¨å
¥åãåæãã¾ãã change
ã¤ãã³ã ã®å¾ã« åæããããã«å¤æ´ããããã« lazy
修飾åã追å ãããã¨ãã§ãã¾ã:
<!-- "input" ã®ä»£ããã« "change" å¾ã«åæãã¾ã -->
<input v-model.lazy="msg">
.number
ã¦ã¼ã¶ã®å
¥åã Number ã¨ãã¦èªåçã«åå¤æãããã¨ãã v-model
ã«ç®¡çãããå
¥åã« number
修飾åã追å ãããã¨ãã§ãã¾ã:
<input v-model.number="age" type="number">
ããã¯ããã°ãã°æç¨ã§ãããªããªãã type=number
ã¨æ¸ããã¨ãã§ããã HTML ã® input è¦ç´ ã® value ã¯å¸¸ã«æååãè¿ãããã§ããããå¤ã parseFloat()
ã§è§£éã§ããªãå ´åã¯ããã¨ã®å¤ãè¿å´ããã¾ãã
.trim
ã¦ã¼ã¶ã®å
¥åãã空ç½ãèªåçã«åãé¤ãããã¨ãã¯ã v-model
ã«ç®¡çãããå
¥åã« trim
修飾åã追å ãããã¨ãã§ãã¾ã:
<input v-model.trim="msg">
ã³ã³ãã¼ãã³ãã® v-model
Vue ã®ã³ã³ãã¼ãã³ãã«ã¾ã ç²¾éãã¦ããªã人ã¯ããã®é¨åãã¹ããããã¦ãã ããã
HTML ã®çµã¿è¾¼ã¿ã® input è¦ç´ ã¯å¸¸ã«ããªãã®è¦æã«åãã¨ã¯éãã¾ããã幸ãã«ããVue ã®ã³ã³ãã¼ãã³ãã使ç¨ããã¨ãå®å
¨ã«ã«ã¹ã¿ãã¤ãºãããåä½ã§åå©ç¨å¯è½ãªç¬èªã® input è¦ç´ çãªãã®ãä½æãããã¨ãã§ãã¾ãããããã®å
¥åã³ã³ãã¼ãã³ã㯠v-model
ã使ç¨ãããã¨ãã§ãã¾ãï¼
ãã詳細ã«ã¤ãã¦ã¯ãã«ã¹ã¿ã å ¥åãã³ã³ãã¼ãã³ãã¬ã¤ãã§åç §ãã¦ãã ããã