Skip to content

Instantly share code, notes, and snippets.

@JimYaaa
JimYaaa / vue.js
Created September 19, 2021 17:25
Vue 3 Multiple v-model
<ChildComponent v-model:title="pageTitle" v-model:content="pageContent" />
// v-model 是下面寫法的語法糖:
<ChildComponent
:title="pageTitle"
@update:title="pageTitle = $event"
:content="pageContent"
@update:content="pageContent = $event"
@JimYaaa
JimYaaa / vue.js
Created September 19, 2021 17:07
Vue 3 v-model arguments
<ChildComponent v-model:title="pageTitle" />
// v-model:title 是下面寫法的語法糖:
<ChildComponent :title="pageTitle" @update:title="pageTitle = $event" />
@JimYaaa
JimYaaa / vue.js
Created September 19, 2021 17:05
Vue 3 v-model arguments
<ChildComponent v-model:title="pageTitle" />
// v-model:title 是下面寫法的語法糖:
<ChildComponent :title="pageTitle" @update:title="pageTitle = $event" />
@JimYaaa
JimYaaa / vue.js
Last active September 19, 2021 17:05
vue 3 v-model
<ChildComponent v-model="pageTitle" />
// v-model 是下面寫法的語法糖:
<ChildComponent
:modelValue="pageTitle"
@update:modelValue="pageTitle = $event"
/>
@JimYaaa
JimYaaa / vue.js
Created September 19, 2021 16:44
Vue 2 .sync modifier
<ChildComponent :title.sync="pageTitle" />
@JimYaaa
JimYaaa / vue.js
Last active September 19, 2021 16:41
vue 2 two way binding prop
// ChildComponent.vue
<script>
export default {
props: {
title: {
type: String,
default: 'Default title'
}
},
@JimYaaa
JimYaaa / vue.js
Last active September 19, 2021 16:15
Vue 2 v-model 3
<ChildComponent :title="pageTitle" @change="pageTitle = $event" />
@JimYaaa
JimYaaa / vue.js
Last active September 19, 2021 16:36
vue 2 two way binding prop
// ChildComponent.vue
export default {
model: {
prop: 'title',
event: 'change'
},
props: {
// title 取代 value
title: {
@JimYaaa
JimYaaa / vue.js
Last active September 19, 2021 16:12
Vue 2 v-model 1
<ChildComponent v-model="pageTitle" />
// v-model 是下面寫法的語法糖:
<ChildComponent :value="pageTitle" @input="pageTitle = $event" />
@JimYaaa
JimYaaa / vue.js
Last active November 26, 2021 09:02
Vue Recursive Component Emit
// Parent Component
<template>
<div>
<parent-recursive-component @recursiveEmit="recursiveEmit" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import ParentRecursiveComponent from './RecursiveComponent'