Home  >  Q&A  >  body text

javascript - scoped in vue single file style is invalid, please give me the reason.

a.vue

<template>
    <p>
        <button class="btn btn-primary">11a.vue</button>
    </p>
</template>
<style scoped>
    @import '../css/bootstrap.css';
    
</style>

b.vue

<template>
    <p>
        <button class="btn btn-primary">b.vue</button>
    </p>
</template>
<style scoped>
    
</style>

But when accessing b.vue, the boostrap style is attached. Scoped does not have the effect of isolating the scope?

仅有的幸福仅有的幸福2734 days ago1213

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-19 10:29:37

    I guess it’s because of @import

    First, let’s take a look at the principle of scoped in vue-loader:
    https://vue-loader.vuejs.org/...

    The page with bootstrap style only means that the bootstrap css has not been processed by vue-loader. Then I searched for the following postcss and @import keywords, and then found the postcss-import plug-in:
    https://www. npmjs.com/package…

    I think if you use this plug-in, it should be able to solve the problem, but I haven’t tested it, it’s just speculation

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:29:37

    Look for the parent page of b, go up level by level, it must be referenced by that page

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:29:37

    Just put it@import '../css/bootstrap.css';去掉;
    换成<style src="../css/bootstrap.css" scoped></style> and it’s ready

    reply
    0
  • Cancelreply