Vuidget

Vuidget

This project is dedicated to all Vue.js developers who tried to embed their application as an external widget and failed, or to those who wish to do so but lack the resources.


It shows how to use advanced Vue.js application as an embeddable HTML widget - meaning an app that contains store, routes, actions, mutations, socket, i18n - simply whatever you choose. Anything used in a traditional single-page application can be used the same way here.


Example of a code in main.js

Before widget setup

new Vue({
  sockets: sockets,
  i18n: i18n.init(lang, translations, CONST.FALLBACK_LOCALE),
  el: '#app',
  render: h => h(App),
  store,
  router
})
      

After widget setup

App.sockets = sockets
App.i18n = i18n.init(lang, translations, CONST.FALLBACK_LOCALE)
App.router = router
App.store = store
Vue.customElement('my-widget', App)
      
Notice that we are not using new Vue() anymore.

<link href="https://vuidget-source.danajanoskova.sk/css/app.css" rel=stylesheet/>

<vue-widget title="Vuidget live example"></vue-widget>

<script src="https://vuidget-source.danajanoskova.sk/js/app.js"></script>


The source code is available at GitHub - https://github.com/DJanoskova/Vuidget


None of this would be possible without https://github.com/karol-f/vue-custom-element created by karol-f

Vue-custom-element is a tiny wrapper around Vue components. It provide seamless way to use it in HTML, plain JavaScript, Vue, React, Angular etc., without manually initialising Vue. It's using power of Web Components' Custom Elements.