简体   繁体   English

Slick.js无法与Polymer 2.0一起使用

[英]Slick.js not working with Polymer 2.0

I try to make my own component with Slick.js library but it seems not working with Polymer 2.0 我尝试使用Slick.js库制作自己的组件,但似乎无法与Polymer 2.0一起使用

I have no error in the debug console and nothing appear on the browser 我在调试控制台中没有错误,并且浏览器上没有任何内容

Here's the code : 这是代码:

<template>

    <link rel="stylesheet" href="../vendors/slick-1.6.0/slick/slick.css">
    <link rel="stylesheet" href="../vendors/slick-1.6.0/slick/slick-theme.css">

    <div id="sliderNews">
        <div><img src="../images/background_baseline.jpeg"></div>
        <div><img src="../images/background_baseline.jpeg"></div>
        <div><img src="../images/background_baseline.jpeg"></div>
        <div><img src="../images/background_baseline.jpeg"></div>
        <div><img src="../images/background_baseline.jpeg"></div>
    </div>

</template>
<script>

    class WorkadvisorModuleNews extends Polymer.Element {

        static get is() { return 'workadvisor-module-news'; }

        static get properties() { return {

            placeholderImg: {
                type: String,
                observer: '_placeholderImgChanged'
            }

        }}

        constructor() {
            super();
        }

        ready() {
            super.ready();
        }

        connectedCallback() {
            super.connectedCallback();
            $(this.$.sliderNews).slick({
                infinite: true,
                arrows: true,
                dots: true,
                slidesToShow: 1
            });
        }
    }

    customElements.define(WorkadvisorModuleNews.is, WorkadvisorModuleNews);

</script>
<script src="../vendors/jquery-3.1.1.min.js"></script>
<script src="../vendors/slick-1.6.0/slick/slick.js"></script>

I've tried to move .js files imported to the index.html but nothing more. 我试图将导入的.js文件移动到index.html,但仅此而已。 Same for .css files. .css文件相同。

Using external stylesheets has been deprecated in Polymer 2. The alternative and preferred way to share styles is with style modules.If you want to learn more about style modules click here . 在Polymer 2中已不建议使用外部样式表。共享样式的另一种方法是,使用样式模块。这是您想要了解的有关样式模块的更多信息, 请单击此处

Basically, to create a style module, you need to wrap your style block in <dom-module> and <template> elements, like this: 基本上,要创建样式模块,需要将样式块包装在<dom-module><template>元素中,如下所示:

<dom-module id="my-style">
  <template>
    <style>
      <!-- Styles to share go here! -->
    </style>
  </template>
</dom-module>

When you create the element that will use the styles, import the style module and include in the opening tag of the style block: 当您创建将使用样式的元素时,请导入样式模块,并将其包含在样式块的开始标记中:

<link rel="import" href="my-style.html">
<dom-module id="my-element">
  <template>
    <style include="my-style">
      <!-- Any additional styles go here -->
    </style>
    <!-- The rest of your element template goes here -->
  </template>
</dom-module>

Demo using slick.js library: http://plnkr.co/edit/PP1uIUICNP4uFZAjZfZb?p=preview 使用slick.js库的演示: http ://plnkr.co/edit/PP1uIUICNP4uFZAjZfZb?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM