简体   繁体   中英

Vue.js dynamic HTML and Vue directives in Sweet Alert 2

new Vue({

    el: '#app',

    data(){

        results: []        
    }   
});

I'm trying to show an alert with Sweet Alert, with an input as a search filter at the top, I then want to filter the results based on what's typed into the input in the alert.

The problem is, Vue directives don't seem to take effect in the Sweet Alert - probably because it's not within the scope of #app . Surprisingly for me, I haven't seen too many issues with this, so I think I'm just doing something wrong.

Is there a way of having Vue directives, events, etc. in the markup of a Sweet Alert?

swal({

    title: 'Something',
    html: `
            <button @click="test">Press Me</button>
          `
});

Thanks

This in case of single variable notice its a backtick not a single qoute

const markup = `
 <div class="person">
    <h2>
        ${person.name}
    </h2>
    <p class="location">${person.location}</p>
    <p class="bio">${person.bio}</p>
 </div>
`;

this is for loops

const markup = `
<ul class="dogs">
    ${dogs.map(dog => `<li>${dog.name} is ${dog.age * 7}</li>`)}
</ul>
`;

reference: http://wesbos.com/template-strings-html/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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