繁体   English   中英

在riotjs中加载外部库

[英]loading external library in riotjs

我有jquery flexslider,它可以进行幻灯片动画。 但问题是在加载DOM之前库已经加载,因此无法触发flexslider的操作。

HTML:

<html>
    <body>
        <home-template></home-template>
        <script src="./views/home-template.html" type=riot/tag></script>
        <script src="bower_components/riot/riot+compiler.min.js" type="text/javascript"></script>
        <script src="assets/js/vendor/jquery-1.11.2.min.js"></script>
        <script src="assets/js/jquery.flexslider-min.js"></script>

        <script>
            riot.mount('*');

            /***************** Flex Slider ******************/

            $('#courses-slider').flexslider({
                animation: "slide",
                prevText: "",
                nextText: "",
                itemWidth: 292,
                itemMargin: 0,
                move: 1
            }); // Courses Slider
        </script>
    </body>
</html>

在角度,我已修复它如下:

.directive('flexslider', function () {
    return {
        link: function (scope, element, attrs) {
            element.flexslider({
                animation: "slide",
            });
        }
    }
})

但是如何在riotjs中修复相同的内容呢?

防暴代码:

<header-template></header-template>
<home-template></home-template>
<footer-template></footer-template>

<script>
        var SharedMixin = {
            observable: riot.observable()
        };
        //creating a data mixin so all tags can access data

        var self = this;
        var DataMixin = {
            data: {
                "status": "Init"
            },
            state: "home",
       }
        function goTo(path) {
            if (path === 'home') {
                console.log(path);
                riot.mount('home-template', {class: 'loader'});
                DataMixin.state = "home";
                riot.update();

            } else if (path === 'about') {
                riot.mount('home-template');
                DataMixin.state = "about";
                riot.update();

            } else if (path === 'instructors') {
                riot.mount('instructors-template');
                DataMixin.state = "instructors";
                riot.update();

            } else if (path === 'contact') {
                riot.mount('contact-template');
                DataMixin.state = "contact";
                riot.update();
            } else {
                console.log("error");
            }
        }

        riot.compile(function () {
            // here tags are compiled and riot.mount works synchronously
            //var tags = riot.mount('*')
            //riot.route.exec(goTo);
            header = riot.mount("header-template");
            footer = riot.mount("footer-template");
            riot.route(goTo);
            riot.route.start(true);
        });

        riot.mixin(DataMixin);
    </script>

你可以在你的防暴标签中调用你的flexslider插件,以便在dom可用时调用它:

<example-tag>
  <p id="courses-slider">Est-ce que j'existe ?</p>

  <script>
    this.on('mount', function(){

        $('#courses-slider').flexslider({
            animation: "slide",
            prevText: "",
            nextText: "",
            itemWidth: 292,
            itemMargin: 0,
            move: 1
        }); // Courses Slider

    });
  </script>
</example-tag>

http://riotjs.com/fr/guide/#montage

暂无
暂无

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

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