Answer the question
In order to leave comments, you need to log in
In VueJs, how to attach styles to specific groups of components?
Hello!
Let's say there is a group of components:
route.js
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/category',
component: Category,
children: {
{ path: '', component: CategoryList },
{ path: '/view', component: CategoryView },
{ path: '/edit', component: CategoryEdit },
}
},
{
path: '/post',
component: Post,
children: {
{ path: '', component: PostList },
{ path: '/view', component: PostView },
{ path: '/edit', component: PostEdit },
}
}
]
})
<style scoped lang="scss">
@import '@/assets/scss/post.scss';
</style>
const Post= resolve => {
require.ensure(['@/views/post/'], () => {
resolve(
require('@/views/post/')
)
})
}
Answer the question
In order to leave comments, you need to log in
You can do this:
But it's better to make separate visual (stupid) components with their own styles that are used only once. And these stupid components you will use on your pages (smart components).
I advise you to read - there is about React, but the very concept of components in React and View is very similar.
PS:
and by the way, in route.js I made it so that the post component was loaded separately by lazy loading
const Post= resolve => {
require.ensure(['@/views/post/'], () => {
resolve(
require('@/views/post/')
)
})
}
const Post= () => import('@/views/post/')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question