const app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
new Vue({
data: {
a: 1
},
created() {
console.log('Created!')
},
mounted() {
console.log('Mounted!')
},
updated() {
console.log('Updated!')
},
destroyed() {
console.log('Destroyed!')
}
})
<span>Message: {{ msg }}</span>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
<div v-bind:id="dynamicId"></div>
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
computed: {
reversedMessage() {
return this.message.split('').reverse().join('')
}
}
watch: {
question(newQuestion, oldQuestion) {
this.answer = 'Waiting for you to stop typing...'
this.debouncedGetAnswer()
}
}
<div v-bind:class="{ active: isActive }"></div>
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<h1 v-if="awesome">Vue is awesome!</h1>
<h1 v-else>Oh no 😢</h1>
<h1 v-show="ok">Hello!</h1>
<ul id="example-1">
<li v-for="item in items" :key="item.id">
{{ item.message }}
</li>
</ul>
<ul id="v-for-object" class="demo">
<li v-for="(value, name) in object">
{{ name }}: {{ value }}
</li>
</ul>
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click="greet">Greet</button>
methods: {
greet(event) {
alert('Hello ' + this.name + '!')
if (event) {
alert(event.target.tagName)
}
}
}
<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>
<input type="checkbox" id="checkbox" v-model="checked">
<label for="checkbox">{{ checked }}</label>
<input type="radio" id="one" value="One" v-model="picked">
<label for="one">One</label>
<input type="radio" id="two" value="Two" v-model="picked">
<label for="two">Two</label>
<span>Picked: {{ picked }}</span>
Vue.component('my-component', {
template: '<div>A custom component!</div>'
})
var ComponentA = { /* ... */ }
new Vue({
components: {
'component-a': ComponentA
}
})
<blog-post title="My journey with Vue"></blog-post>
Vue.component('my-component', {
props: {
propA: Number,
propB: [String, Number],
propC: {
type: String,
required: true
},
propD: {
type: Number,
default: 100
},
propE: {
type: Object,
default() {
return { message: 'hello' }
}
}
}
})
Vue.component('custom-input', {
props: ['value'],
template: `
<input
v-bind:value="value"
v-on:input="$emit('input', $event.target.value)"
>
`
})
<navigation-link url="/profile">
Your Profile
</navigation-link>
<base-layout>
<template v-slot:header>
<h1>Here might be a page title</h1>
</template>
<p>A paragraph for the main content.</p>
<template v-slot:footer>
<p>Here's some contact info</p>
</template>
</base-layout>
<component v-bind:is="currentTabComponent"></component>
Vue.component('async-example', function (resolve, reject) {
setTimeout(function () {
resolve({
template: '<div>I am async!</div>'
})
}, 1000)
})
<transition name="fade">
<p v-if="show">hello</p>
</transition>
.fade-enter-active, .fade-leave-active {
transition: opacity .5s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
var myMixin = {
created() {
this.hello()
},
methods: {
hello() {
console.log('hello from mixin!')
}
}
}
var Component = Vue.extend({
mixins: [myMixin]
})
Vue.directive('focus', {
inserted: function (el) {
el.focus()
}
})
Vue.filter('capitalize', function (value) {
if (!value) return ''
value = value.toString()
return value.charAt(0).toUpperCase() + value.slice(1)
})
Vue.use(MyPlugin, { someOption: true })
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
}
},
actions: {
increment (context) {
context.commit('increment')
}
},
getters: {
doubleCount: state => {
return state.count * 2
}
}
})
const router = new VueRouter({
routes: [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]
})
const app = new Vue({
router
}).$mount('#app')
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
router.push('home')
router.push({ path: 'home' })
router.push({ name: 'user', params: { userId: '123' } })
2024 © All rights reserved - buraxta.com