framework7io / framework7

Full featured HTML framework for building iOS & Android apps
http://framework7.io
MIT License
18.13k stars 3.23k forks source link

How to use Template7.compile to parse @click="$root.helloworld ()" #3287

Closed momoca closed 5 years ago

momoca commented 5 years ago

js file : packages/core/js/framework7.bundle.min.js app:

app = new Framework7({
    id: 'com.xxx.test',
    root: '#app',
    theme: 'auto',
    data: function() {
        return {
            username: 'vladimir',
            firstName: 'Vladimir',
            lastName: 'Kharlampidi'
        };
    },
    on: {
        init: function() {},
    },
    methods: {
        helloWorld: function() {
            app.dialog.alert('Hello World!');
        },
    },
    routes: routes,
    popup: {
        closeOnEscape: true,
    },
    sheet: {
        closeOnEscape: true,
    },
    popover: {
        closeOnEscape: true,
    },
    actions: {
        closeOnEscape: true,
    },
    lazy: {
        threshold: 50,
        sequential: false,
    },
});

page:

<!--html template-->
<template>
    <div class="page">
        ...
    </div>
</template>
<script>
return {
    on: {
        pageInit: function(page) {
            var self = this;
            if (!self.popup) {
                self.popup = self.$app.popup.create({
                    content: (Template7.compile('<div class="popup register-popup"><div class="page"><div class="page-content"><a @click="$root.helloWorld()">{{$root.firstName}}</a></div></div></div>'))(self)
                });
            }
            self.popup.open();
        }
    }
}
</script>

compile html:

<div class="page-content"><a @click="$root.helloWorld()" class="">Vladimir</a></div>

How to parse @click?

nolimits4web commented 5 years ago

It can't be parsed like that, it is a Router component feature only. So make this popup routable and use component for it, or add click handlers manually

nolimits4web commented 5 years ago

Do you want to ask a question? Are you looking for support? The Framework7 forum and Stack Overflow are the best places for getting support

Please, don't use GitHub issues for questions