javascript - 错误 [Vue 警告] : option "el" can only be used during instance creation with the `new` keyword

标签 javascript vue.js

我有以下缩写的 vue 组件:

    <template>
    <section>
        <v-card class="mx-auto" color="#26c6da" dark max-width="1200">
        <v-carousel >
            <v-carousel-item v-for="(item,i) in items" :key="i" v-html="item.content"> </v-carousel-item>
        </v-carousel>
        </v-card>
    </section>
    </template>


    <script>
    ...........................
    console.log(res);
    export default {
        el: '#app',
        data: function() {
        return {
            items: res
        };
        }
    };
    </script>

    <style scoped>
    #app iframe {
        width: 100%;
        height: 500px;
    }
    </style>

我想在底部添加 css 来控制轮播的外观。为此,我尝试声明“el”属性并将 css 卡在其上。我收到标题中的错误。我该如何解决这个问题?

最佳答案

您的组件中不需要 el: '#app',。这仅在启动新的 Vue 应用程序时使用。

此外,根据 style 标签上的 scoped 属性,您的 css 将自动限定为该组件实例。

如果 Iframe 嵌套在另一个组件中,您将需要使用深度选择器:

<style scoped>
    /deep/ iframe {
        width: 100%;
        height: 500px;
    }
</style>

https://vue-loader.vuejs.org/guide/scoped-css.html#deep-selectors

关于javascript - 错误 [Vue 警告] : option "el" can only be used during instance creation with the `new` keyword,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56069242/

相关文章:

javascript - 如何将 jQuery 添加到 VuePress 文件中

javascript - 如何使用数据库中的值执行 JavaScript 事件?

javascript - 无法使用 Pinia 调用 API 内的存储

vue.js - 如何使用 Vue.js 在拆分组中呈现列表?

javascript - 带下拉菜单的 angularjs ui.router activestate

javascript - 使用 src=require() 时来自 webpack 的 Vue.js 错误 "Cannot find module ' ./undefined'"

javascript - 如何在 Vue 的功能组件中访问 mixin?

javascript - 是否可以使用 WebGL 最大纹理大小?

javascript - 跑马灯标签开始位置

javascript - React Setstate 在 JSON 化后使我的状态项未定义