使用“<样式范围的>"在Nuxt.js(SPA)中 [英] Use of '<style scoped>' in Nuxt.js (SPA)

查看:54
本文介绍了使用“<样式范围的>"在Nuxt.js(SPA)中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用nuxt.js/express启动项目.

I start the project with nuxt.js / express.

我们已经为nuxt.js中的每个组件(.vue)开发了样式范围.因此,在routing时,该属性会覆盖在相同的类名(样式)上,因此页面无法正确显示.

We have developed style scoped for each component (.vue) in nuxt.js. So, when routing , the property is overlaid on the same class name (style), so the page does not display properly.

1.样式范围"的正确用法是什么?

2.还是路由过程应该是< a> 而不是< nuxt-link> ?

2. Or should the routing process be <a> rather than <nuxt-link>?

推荐答案

  1. 样式范围"的正确用法是什么?

< style scoped></style> 表示法并不明确,正如 scoped 属性所暗示的那样,此范围内定义的所有CSS元素仅适用于当前组件.如果CSS元素全局存在,则具有相同名称和类型的作用域优先(即,它会覆盖全局定义的CSS元素).

The <style scoped></style> notation is not ambiguous, as the scoped attribute suggests, all the CSS elements defined within this scope apply only to the current component. If the CSS element exists globally, the scoped one -having the same name and type- takes precedence, that is, it overrides the globally defined CSS element.

例如,让我们在/components文件夹中定义3个组件Component1.vue,Component2.vue,Component3.vue:

For example, let us define in /components folder 3 components Component1.vue, Component2.vue, Component3.vue:

Component1.vue :

<template>                                                                                                                                             
  <div class="yellow-text">Component 1</div>                                                                                                           
</template>                                                                                                                                            

<script>                                                                                                                                               
export default {                                                                                                                                       
  name: 'Component1'                                                                                                                                   
}                                                                                                                                                      
</script>  
<style>
.yellow-text {
  color: yellow;
}
</style>   

Component2.vue:

<template>                                                                                                                                             
  <div class="yellow-text">Component 2</div>                                                                                                           
</template>                                                                                                                                            

<script>                                                                                                                                               
export default {                                                                                                                                       
  name: 'Component2'                                                                                                                                   
}                                                                                                                                                      
</script>  
<style scoped>
.yellow-text {
  color: red;
}
</style>             

Component3.vue:

<template>                                                                                                                                             
  <div class="yellow-text">Component 3</div>                                                                                                           
</template>                                                                                                                                            

<script>                                                                                                                                               
export default {                                                                                                                                       
  name: 'Component3'                                                                                                                                   
}                                                                                                                                                      
</script>  

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆