[Vuejs]-JQuery function vs Vue JS – for UI component development

0👍

There’s actually a discussion on this very question in an issue on the vue-sweetalert2 repo.

Some people prefer using a Vue wrapper around libraries in order to make using them more ‘vue-like’.

Sometimes such wrappers add custom components to allow using them in a declarative manner, which can make them worth considering, but you always have to consider that you’re adding an additional dependency that may not be updated as frequently as the library it’s wrapping.

In this particular case, you’re really not gaining anything from using the wrapper, and (as mentioned in the issue comments) you’d be better off making the dependency on sweetalert more explicit with an import statement:

<template>
    <button v-on:click="showAlert">Hello world</button>
</template>

<script>
import swal from 'sweetalert2'
export default {
    data() {
        return {};
    },
    methods: {
        showAlert(){
            // Use sweetalret2
            swal('Hello Vue world!!!');
        }
    }
}
</script>

Leave a comment