A
A
Andrej Sharapov2019-07-08 17:49:45
JavaScript
Andrej Sharapov, 2019-07-08 17:49:45

How to refer to a dynamically created vue component?

Actually a subject.
Created a vue component and wrapped it in a dynamically created object. It is necessary that the block is displayed only at a resolution > 768px. The script works, but when I enter object data, -__- stops working. Tell me, where is the error?

(function () {

    Vue.component('footer-bar', {
        template: `
        <div id="footer-bar">
            This block nav
        </div>
        `
    })

    const bar = document.createElement('div');
    bar.id = 'navbar';
    const body = document.body;
    body.appendChild(bar);

    new Vue({
        el: '#navbar',
        template: `
        <div id="navbar">
            <footer-bar></footer-bar>
        </div>
        `
    })

    function smallMedia(sm) {
        if (sm.matches) {
            bar.style.display = "block";
        } else {
            bar.style.display = "none";
        }
    }

    const mqSm = window.matchMedia("(min-width: 768px)");
    smallMedia(mqSm);
    mqSm.addListener(smallMedia);

})();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Planet_93, 2019-07-08
@Planet_93

To solve these problems, CSS has a media property :

@media screen and (max-width:350px) {
    .object {
        display: none;
    }
}

A
Andrej Sharapov, 2019-07-08
@Madeas

I decided. Created a new variable const db = document.getElementById('navbar');and it worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question