簡體   English   中英

使用 render/createElement 將單選按鈕鏈接到 Vue 中的數據

[英]Linking radio buttons to data in Vue with render/createElement

在 Vue 中使用 render/createElement 函數創建單選按鈕時,如何將所選單選按鈕的值鏈接到模型中data對象中的預期變量?

您將不得不手動進行。 請參閱 Vue 在渲染功能頁面上關於v-model的文檔。

渲染函數中沒有直接對應的v-model - 您必須自己實現邏輯

這是一個非常失敗的示例,它將發出單擊的無線電輸入的值。 您仍然需要解決確保發出的值是實際選擇的收音機以及設置選擇的值(如果指定為道具)。

 const foo = { props: ["name"], render(h) { const $this = this; const arr = ["a", "b", "c"]; return h("div", {}, arr.map(v => h("label", [h("input", { domProps: { type: "radio", name: this.name }, on: { click() { $this.$emit("change", v); } } }), h("span", v)]))); } }; const app = new Vue({ el: "#app", data() { return { fizz: true }; }, components: { foo }, methods: { onChange(e) { console.log(e); } } });
 <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script> <div id="app"> <foo name="some" @change="onChange"></foo> </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM