父層
<BasicCheckboxGroup v-model="selected"
:options="options" />
子層
<template>
<div v-for="(option, key) in options" :key="key" class="flex">
<input
v-model="selected"
type="checkbox"
:option="option"
:value="option.id"
@checked="$emit('update:modelValue', selected)"
/>
<label>{{ option.name }}</label>
<div>---{{ selected }}---</div>
</div>
</template>
子層接值
interface Props {
selected: string[]
}
const props = withDefaults(defineProps<Props>(), {
selected: () => [],
})
傳值結果 X
------
const selected = ref<string[]>([])
傳值結果 O
props 只能 readonly,不能 mutate,目的只是給 props 預設值沒有衝突,建議不要用來存 props 的變數名稱
不要跟 props 的變數一樣
Test Util Vue 參考網址 Github專案原始碼 測試練習 Counter 等值測試
Jun 10, 2022Vue.js 和 Composition API 入門 Vue.js 基礎與組合 API 課程涵蓋: 雙向數據綁定簡介 模板語法和表達式 Vue 指令、循環和條件渲染 Vue 開發工具 處理用戶輸入 處理事件 Vue.js 方法和計算屬性
Jun 8, 2022#1 Introduction #1 Tutorial 教程 #1 Practice 練習 * 引入defineComponent的方式 import { defineComponent } from "vue"; export default defineComponent({ name: "App", components: {},
Jun 6, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up