我在我的組件的樣式表上.title和.description樣式表中添加了一些樣式test,但不確定為什么不應用該樣式。
const test = Vue.component("test", {
template: `<div class="test">
<span class="title">{{title}}</span>
<div class="description">{{description}}</div>
</div>`,
props: {
id: Number,
title: String,
description: String,
},
});

HelloWorld.vue
<template>
<div id="hello">
<test
v-for="item in steps"
:key="item.id"
:id="item.id"
:title="item.title"
:description="item.description"
/>
</div>
</template>
<script>
import Vue from "vue";
const test = Vue.component("test", {
template: `<div >
<span >{{title}}</span>
<div >{{description}}</div>
</div>`,
props: {
id: Number,
title: String,
description: String,
},
});
export default {
components: {
test,
},
data() {
return {
steps: [
{
id: 1,
title: "What is Lorem Ipsum?",
description:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
},
],
};
},
};
</script>
<style scoped lang="scss">
#hello {
display: flex;
flex-direction: column;
.test {
/* style applied */
text-align: left;
margin-top: 10px;
.title {
/* style not applied */
font-size: 50px;
color: orange;
}
.description {
/* style not applied */
font-size: 10px;
line-height: 12px;
color: red;
}
}
}
</style>
Codesandbox:https ://codesandbox.io/s/amazing-flower-rcvob ? file =/ src/components/HelloWorld.vue
uj5u.com熱心網友回復:
使用作用域樣式時,樣式僅適用于相應模板中的直接元素。在title和description元素是的子元素<test>組成部分,是由范圍的款式另一個組件的影響。
::v-deep如果要將樣式應用于另一個組件的子元素,則需要使用:
#hello {
.test {
&::v-deep .title {
color: red;
}
}
}
不過,我無法讓它在 codeandbox 中作業。可能是配置問題。另見深度選擇器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/353956.html
標籤:javascript html css Vue.js
