ã¬ã¤ã
åºæ¬çãªä½¿ãæ¹
- ã¤ã³ã¹ãã¼ã«
- ã¯ããã«
- 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å¹´11æ7æ¥
äºææ§ã®æ³¨æ
Vue.js 㯠IE8 ã§ã¯ã·ã (shim) ãã§ããªã ECMAScript 5 ã®æ©è½ã使ç¨ãããããIE8 ã¨ãã以ä¸ã®ãã¼ã¸ã§ã³ããµãã¼ããã¦ãã¾ãããããããªãããECMAScript 5 æºæ ã®ãã©ã¦ã¶ ã¯å ¨ã¦ãµãã¼ããã¦ãã¾ãã
ã»ãã³ãã£ãã¯ãã¼ã¸ã§ãã³ã°
Vue ã¯ããã¹ã¦ã®å ¬å¼ããã¸ã§ã¯ãã«ããã¦ããã¥ã¡ã³ãåãããæ©è½ãåä½ã«ã¤ãã¦ã¯ãã»ãã³ãã£ãã¯ãã¼ã¸ã§ãã³ã° ã«æºæ ãã¦ãã¾ããããã¥ã¡ã³ãåããã¦ããªãåä½ãå ¬éããã¦ããå é¨è©³ç´°ã«ã¤ãã¦ã¯ããªãªã¼ã¹ãã¼ã ã«å¤æ´ç¹ãè¨è¼ããã¦ãã¾ãã
ãªãªã¼ã¹ãã¼ã
ææ°ã®å®å®ãã¼ã¸ã§ã³: 2.7.11
åãã¼ã¸ã§ã³ã®è©³ç´°ãªãªãªã¼ã¹ãã¼ãã¯ãGitHub ã§å ¥æã§ãã¾ãã
Vue Devtools
Vue ã使ç¨ããå ´åã¯ããã©ã¦ã¶ã« Vue Devtools ãã¤ã³ã¹ãã¼ã«ãããã¨ããå§ããã¾ããããã«ããã Vue ã¢ããªã±ã¼ã·ã§ã³ãããã¦ã¼ã¶ã¼ãã¬ã³ããªã¼ãªã¤ã³ã¿ã¼ãã§ã¼ã¹ã§èª¿æ»ããããã°ãããã¨ãå¯è½ã«ãªãã¾ãã
<script>
ç´æ¥çµã¿è¾¼ã¿
ãã¦ã³ãã¼ãã script ã¿ã°ã§èªã¿è¾¼ãã§ãã ãããVue
ã¯ã°ãã¼ãã«å¤æ°ã¨ãã¦ç»é²ããã¾ãã
éçºä¸ã¯æ¬çªãã¼ã¸ã§ã³ã使ç¨ããªãã§ãã ããã è¦åãä¸è¬çãªééããè¦éãå¯è½æ§ãããã¾ã!
éçºãã¼ã¸ã§ã³è¦ååºåã¨ãããã°ã¢ã¼ããã
æ¬çªãã¼ã¸ã§ã³è¦ååºåãªãã 37.50 KB min+gzip
CDN
ãããã¿ã¤ãã³ã°ãå¦ç¿ãç®çã¨ããå ´åã¯ã以ä¸ã®ããã«ãã¦ææ°ãã¼ã¸ã§ã³ã使ããã¨ãã§ãã¾ã:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
æ¬çªç°å¢ã§ã¯ãæ°ãããã¼ã¸ã§ã³ã«ããæå³ããªãä¸å ·åãé¿ãããããç¹å®ã®ãã¼ã¸ã§ã³çªå·ã¨ãã«ãçªå·ã«ãªã³ã¯ãããã¨ããå§ããã¾ã:
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
ããããã¤ãã£ãã® ES Modules ã使ã£ã¦ãããªããES Modules äºæã®ãã«ããããã¾ã:
<script type="module">
import Vue from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.esm.browser.js'
</script>
cdn.jsdelivr.net/npm/vue 㧠NPM ããã±ã¼ã¸ã®ã½ã¼ã¹ãåç §ãããã¨ãã§ãã¾ãã
Vue 㯠unpkg ã¾ã㯠cdnjs ä¸ã§ãå©ç¨å¯è½ã§ã(cdnjs ã¯åæã«å°ãæéãããããããææ°çã§ã¯ãªãå¯è½æ§ãããã¾ã)ã
Vue ã®ãã¾ãã¾ãªãã«ãã«ã¤ã㦠ãèªã¿ãå
¬éããããµã¤ãã§ã¯æ¬çªãã¼ã¸ã§ã³ã使ç¨ããvue.js
ã vue.min.js
ã«ç½®ãæãã¦ãã ãããããã¯éçºä½é¨ã®ä»£ããã«ã¹ãã¼ãã®ããã«æé©åãããå°ããªãã«ãã§ãã
NPM
Vue.js ã«ãã大è¦æ¨¡ã¢ããªã±ã¼ã·ã§ã³ãæ§ç¯ããã¨ãã«ã¯ãNPM ãå©ç¨ããã¤ã³ã¹ãã¼ã«ãæ¨å¥¨ãã¦ãã¾ãã Webpack ã¾ã㯠Browserify ã®ãããªã¢ã¸ã¥ã¼ã«ãã³ãã©ã¨ãã¾ãçµã¿åããããã¾ãã Vue ã¯åä¸ãã¡ã¤ã«ã³ã³ãã¼ãã³ã ãä½æããããã®ãä»éãããã¼ã«ãæä¾ãã¦ãã¾ãã
# ææ°ã®å®å®ç
$ npm install vue
CLI
大è¦æ¨¡ãªã·ã³ã°ã«ãã¼ã¸ã¢ããªã±ã¼ã·ã§ã³éçºã®ããã®è¶³å ´ãç´ æ©ãçµãããã«ãVue.js ã§ã¯ ãªãã£ã·ã£ã« CLI ãæä¾ãã¾ãããã® CLI ã«ã¯ã¢ãã³ãªããã³ãã¨ã³ãã¯ã¼ã¯ããã¼ã®ããã®ãããã«ä½¿ãããã«ãè¨å®ãç¨æãã¦ãã¾ããããããªãã¼ããä¿åæã®ãªã³ãã製åãªãªã¼ã¹ç¨ãã«ããã§ããããã«ãªãã¾ã§ã«ãã»ãã®æ°åãããããã¾ããããã詳細㯠Vue CLI ããã¥ã¡ã³ã ãåç §ãã¦ãã ããã
CLI 㯠Node.js ããã³é¢é£ãããã«ããã¼ã«ã«é¢ããäºåç¥èãåæã¨ãã¦ãã¾ããVue ã¾ãã¯ããã³ãã¨ã³ããã«ããã¼ã«ãåãã¦ä½¿ç¨ãã¦ããå ´åãCLI ã使ç¨ããåã«ããã«ããã¼ã«ãªãã§ã¬ã¤ããåç §ãããã¨ãå¼·ããå§ããã¾ãã
ãã¾ãã¾ãªãã«ãã«ã¤ãã¦
NPM ããã±ã¼ã¸ã® dist/
ãã£ã¬ã¯ã㪠ã§ã¯ Vue.js ã®å¤ãã®ãã¾ãã¾ãªãã«ããè¦ã¤ããã¾ãããããã®éãã®æ¦è¦ã¯ä»¥ä¸ã®éãã§ã:
UMD | CommonJS | ES Module (ãã³ãã©ç¨) | ES Module (ãã©ã¦ã¶ç¨) | |
---|---|---|---|---|
å®å ¨ | vue.js | vue.common.js | vue.esm.js | vue.esm.browser.js |
ã©ã³ã¿ã¤ã éå® | vue.runtime.js | vue.runtime.common.js | vue.runtime.esm.js | - |
å®å ¨ (æ¬çªç¨) | vue.min.js | - | - | vue.esm.browser.min.js |
ã©ã³ã¿ã¤ã éå® (æ¬çªç¨) | vue.runtime.min.js | - | - | - |
ç¨èª
å®å ¨: ã³ã³ãã¤ã©ã¨ã©ã³ã¿ã¤ã ã®ä¸¡æ¹ãå«ã¾ãããã«ãã§ãã
ã³ã³ãã¤ã©: ãã³ãã¬ã¼ãæååã JavaScript ã¬ã³ããªã³ã°é¢æ°ã«ã³ã³ãã¤ã«ããããã®ã³ã¼ãã§ãã
ã©ã³ã¿ã¤ã : Vue ã¤ã³ã¹ã¿ã³ã¹ã®ä½æãã¬ã³ããªã³ã°ãä»®æ³ DOM ã®å¤æ´ãªã©ã®ããã®ã³ã¼ãã§ããåºæ¬çã«ã³ã³ãã¤ã©ãé¤ãå ¨ã¦ã®ãã®ã§ãã
UMD: UMD ãã«ãã¯
<script>
ã¿ã°ã«ãã£ã¦ãã©ã¦ã¶ã«ç´æ¥å©ç¨ããã¾ããhttps://cdn.jsdelivr.net/npm/vue ã® jsDelivr CDN ããã®æ¢å®ã®ãã¡ã¤ã«ã¯ ã©ã³ã¿ã¤ã + ã³ã³ãã¤ã© UMD ãã«ã (vue.js
) ã§ããCommonJS: CommonJS ãã«ã㯠browserify ã webpack 1 ã®ãããªå¤ããã³ãã©ã§ã®å©ç¨ãæå³ãã¦ãã¾ãããããã®ãã³ãã© (
pkg.main
) ã®ããã®æ¢å®ã®ãã¡ã¤ã«ã¯ã©ã³ã¿ã¤ã éå® CommonJS ãã«ã (vue.runtime.common.js
) ã§ããES Module: ãã¼ã¸ã§ã³ 2.6 ãã Vue 㯠2 種é¡ã® ES Modules (ESM) ãã«ããæä¾ãã¾ã:
ãã³ãã©ç¨ ESM: webpack 2 ã Rollup ã®ãããªã¢ãã³ãã³ãã©ã§ã®å©ç¨ãæ³å®ãã¦ãã¾ããESM ãã©ã¼ãããã¯ããã³ãã©ã âtree-shakingâ ãå®è¡ãã¦æçµãã³ãã«ããæªä½¿ç¨ã³ã¼ããé¤å»ããããããã«ãéç解æã§ããè¨è¨ã«ãªã£ã¦ãã¾ãããããã®ãã³ãã© (
pkg.module
) ã®ããã®æ¢å®ã®ãã¡ã¤ã«ã¯ãã©ã³ã¿ã¤ã éå® ES Module ãã«ã (vue.runtime.esm.js
) ã§ãããã©ã¦ã¶ç¨ ESM (2.6 以éã®ã¿): ã¢ãã³ãã©ã¦ã¶ã§ã®
<script type="module">
ã«ããç´æ¥ã¤ã³ãã¼ããæ³å®ãã¦ãã¾ãã
ã©ã³ã¿ã¤ã + ã³ã³ãã¤ã©ã¨ã©ã³ã¿ã¤ã éå®ã®éã
ããã¯ã©ã¤ã¢ã³ãã§ãã³ãã¬ã¼ããã³ã³ãã¤ã«ããå¿
è¦ããã (ä¾ãã°ã template
ãªãã·ã§ã³ã«æååã渡ããããã㯠DOM å
ã® HTML ããã³ãã¬ã¼ãã¨ãã¦å©ç¨ãè¦ç´ ã«ãã¦ã³ããã) å ´åã¯ãã³ã³ãã¤ã©ããªãã¡å®å
¨ãã«ããå¿
è¦ã§ãã
// ããã¯ã³ã³ãã¤ã©ãå¿
è¦ã§ã
new Vue({
template: '<div>{{ hi }}</div>'
})
// ããã¯ã³ã³ãã¤ã©ã¯å¿
è¦ããã¾ãã
new Vue({
render (h) {
return h('div', this.hi)
}
})
vue-loader
ã vueify
ãå©ç¨ããå ´åã *.vue
ãã¡ã¤ã«ã«ä¸ã®ãã³ãã¬ã¼ãã¯ãã«ãæã« JavaScript ã«äºåã³ã³ãã¤ã«ããã¾ããæçµææç©ã®ä¸ã«ã³ã³ãã¤ã©ã¯æ¬å½ã«å¿
è¦ãªãããããã£ã¦ã©ã³ã¿ã¤ã éå®ãã«ããå©ç¨ãããã¨ãåºæ¥ã¾ãã
ã©ã³ã¿ã¤ã éå®ãã«ãã¯å®å ¨ãã«ãã«æ¯ã¹ããã 30% 軽éãªãããå©ç¨ã§ããã¨ãã«ã¯ãããå©ç¨ããã»ããè¯ãã§ããããããã§ããªãå®å ¨ãã«ããå©ç¨ãããå ´åã¯ããã³ãã©ã§ã¨ã¤ãªã¢ã¹ãè¨å®ããå¿ è¦ãããã¾ãã
Webpack
module.exports = {
// ...
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' webpack 1 ç¨
}
}
}
Rollup
const alias = require('rollup-plugin-alias')
rollup({
// ...
plugins: [
alias({
'vue': require.resolve('vue/dist/vue.esm.js')
})
]
})
Browserify
ããã¸ã§ã¯ãã® package.json
ã«è¿½å ãã¦ãã ãã:
{
// ...
"browser": {
"vue": "vue/dist/vue.common.js"
}
}
Parcel
ããã¸ã§ã¯ãã® package.json
ã«è¿½å ãã¦ãã ãã:
{
// ...
"alias": {
"vue" : "./node_modules/vue/dist/vue.common.js"
}
}
éçºã¢ã¼ãã¨æ¬çªã¢ã¼ãã®éã
éçº/æ¬çªã¢ã¼ã㯠UMD ãã«ãã§ã¯ãã¼ãã³ã¼ãããã¦ãã¾ã: éçºç¨ã§ã¯é縮å°ãã¡ã¤ã«ã§ãæ¬çªç¨ã§ã¯å§ç¸®ããããã¡ã¤ã«ã«ãªã£ã¦ãã¾ãã
CommonJS 㨠ES Module ãã«ãã¯ãã³ãã©ã§ã®å©ç¨ãæå³ãã¦ãããããå§ç¸®ãã¼ã¸ã§ã³ãæä¾ãã¦ãã¾ãããããªãã®è²¬ä»»ã§æçµææç©ãå§ç¸®ããå¿ è¦ãããã¾ãã
CommonJS 㨠ES Module ãã«ãã¯ã¾ããå®è¡ã¢ã¼ãã決ããããã« process.env.NODE_ENV
ãç´æ¥ãã§ãã¯ããããã«ä¿æããã¦ãã¾ãã Vue ãå®è¡ããã¢ã¼ããã³ã³ããã¼ã«ããããã«é©åãªãã³ãã©è¨å®ãå©ç¨ãã¦ãããã®ç°å¢å¤æ°ãç½®æããããã«ãã¦ãã ããã process.env.NODE_ENV
ãç½®æãããã¨ã§ã UglifyJS ã®ãããªå§ç¸®ãã¼ã«ãéçºç¨ã³ã¼ãã®ãããã¯ãåé¤ããæçµãã¡ã¤ã«ã®ãµã¤ãºãåæ¸ãããã¨ãã§ãã¾ãã
Webpack
Webpack 4 以éã§ã¯ãmode
ãªãã·ã§ã³ã使ç¨ã§ãã¾ã:
module.exports = {
mode: 'production'
}
ããããWebpack 3 以åã§ã¯ãDefinePlugin ã使ç¨ããå¿ è¦ãããã¾ã:
var webpack = require('webpack')
module.exports = {
// ...
plugins: [
// ...
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
}
Rollup
rollup-plugin-replace ã¯ä»¥ä¸ã®ããã«ãã¦å©ç¨ãã¾ã:
const replace = require('rollup-plugin-replace')
rollup({
// ...
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}).then(...)
Browserify
ã°ãã¼ãã«ãª envify transform ã¯ä»¥ä¸ã®ããã«ãã¦ãã³ãã©ã«é©ç¨ãã¾ã:
NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js
ãããã¯ã·ã§ã³ç°å¢ã¸ã®é ä¿¡ã®ãã³ã ãåèã«ãã¦ãã ããã
CSP ç°å¢
Google Chrome ã¢ããªã®ãããªããç°å¢ã§ã¯ãContent Security Policy (CSP) ãå¼·å¶ããããã¦å¼ãè©ä¾¡ããããã« new Function()
ã®ä½¿ç¨ãç¦æ¢ãã¦ãã¾ãããã³ãã¬ã¼ãã®ã³ã³ãã¤ã«ã¯ãå®å
¨ãã«ãã«ä¾åããããããããã®ç°å¢ã§ã¯ä½¿ç¨ã§ãã¾ããã
ä¸æ¹ã§ã¯ãã©ã³ã¿ã¤ã éå®ãã«ãã§ã¯ CSP ã«æºæ ãã¦ãã¾ãã Webpack + vue-loader ã¾ã㯠Browserify + vueify ã§ã©ã³ã¿ã¤ã éå®ãã«ãã使ç¨ããå ´åã¯ããã³ãã¬ã¼ã㯠CSP ç°å¢ã§ãå®ç§ã«åä½ãã render
é¢æ°ã«ããªã³ã³ãã¤ã«ããã¾ãã
éçºçã®ãã«ã
éè¦ GitHub ä¸ã® /dist
ãã©ã«ãã«åå¨ãããã«ãããããã¡ã¤ã«ã¯ããªãªã¼ã¹æã«ã®ã¿ãã§ãã¯ã¤ã³ããã¾ãã GitHub ä¸ã®ææ°ã®ã½ã¼ã¹ã³ã¼ããã Vue ã使ç¨ããããã«ã¯ãããªãèªèº«ãããããã«ãããªããã°ãªãã¾ããï¼
git clone https://github.com/vuejs/vue.git node_modules/vue
cd node_modules/vue
npm install
npm run build
Bower
Bower ã§ã¯ UMD ãã«ãã®ã¿ã§å©ç¨ã§ãã¾ãã
# ææ°ã®å®å®æ¿
$ bower install vue
AMD ã¢ã¸ã¥ã¼ã«ãã¼ã
å ¨ã¦ã® UMD ãã«ã㯠AMD ã¢ã¸ã¥ã¼ã«ã¨ãã¦ç´æ¥å©ç¨ã§ãã¾ãã