// ...
computed: {
fullName: {
// getter
get: function () {
return this.firstName + ' ' + this.lastName
},
// setter
set: function (newValue) {
var names = newValue.split(' ')
this.firstName = names[0]
this.lastName = names[names.length - 1]
}
}
}
// ...
$ npm install -g vue-cli
$ vue init [template-name] [project-name]
| $ vue init webpack-simple testapp
| $ cd testapp
| $ npm install
| $ npm run dev
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
<template>
<div id="app">
<h1>Hello World</h1>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<style>
</style>
module.exports = {
render: function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _vm._m(0)
},
staticRenderFns: [function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('div', {
attrs: {
"id": "app"
}
}, [_c('h1', [_vm._v("Hello World")])])
}]
}
});
$ npm run build
$ create-react-app
$ ...
$ yarn run build
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
<template>
<div id="app">
<h1>Hello World</h1>
</div>
</template>
<script>
export default {
import Header from './components/Header.vue';
name: 'app',
components: {
appHeader: Header
},
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<style>
</style>
<template lang='pug'>
div
button.btn.btn-success Click me
</template>
<script>
...
</script>
<style lang='scss'>
$text-color: black;
div {
color: black;
}
</style>
<template>
...
</template>
<script>
...
</script>
<style scoped>
$text-color: black;
div {
color: black;
}
</style>
src/
-- components/
---- shared/
------ Header.vue
---- Dropdown.vue
---- auth/
------ SignIn.vue
------ SignUn.vue
main.js
App.vue
src/
-- auth/
------ SignIn.vue
------ SignUn.vue
-- user/
------ Profile.vue
------ EditProfile.vue
-- shared/
------ Dropdown.vue
main.js
App.vue
// main.js
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
export const eventBus = new Vue();
<template>
...
</template>
<script>
import { eventBus } from '../main';
export default {
};
</script>
Vue.directive('highlight', {
bind (el, binding, vnode) {
// Once directive is attached
},
inserted (el, binding, vnode) {
// Inseted in a parent node
},
updated (el, binding, vnode, oldVnode) {
// Once component is updated (without children)
},
componentUpdated (el, binding, vnode, oldVnode) {
// Once component is updated (with children)
},
unbind (el, binding, node) {
// Once directive is removed
}
});
import Vue from 'vue'
import App from './App.vue'
import VueResouce from 'vue-reource';
Vue.use(VueResource); // it's how to use plugins
new Vue({
el: '#app',
render: h => h(App)
})