我試圖在 Vue 3 中向我的行內 :style 傳遞一個道具,但由于某種原因我無法做到這一點。這是我的代碼。任何幫助表示贊賞。
<template>
<div style="width: 100vw;" :style="{'min-height': props.rem}"></div>
</template>
const props = defineProps({
rem: Number
})
uj5u.com熱心網友回復:
嘗試將“rem”添加到min-height樣式道具:
const app = Vue.createApp({
data() {
return {
nr: 10,
};
},
})
app.component('child', {
template: `
<div style="width: 100vw;" :style="{'min-height': rem 'rem'}"> rem = {{ rem }}</div>
`,
props: {
'rem': {
type: Number,
default: 5
}
},
})
app.mount('#demo')
.child {
background-color: purple;
}
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
<child :rem="nr"></child>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/469196.html
下一篇:元素從容器頂部溢位flex
