I’ve tried playing with Vue in Frappe and ran into a problem.
How do I import components to extend a new Vue instance for my Page, generated with the Page DocType? I can’t use ES6 imports due to the Page script not being appended as type=module
.
I’ve implemented imports with with callbacks and frappe.require(), but it feels like a hacky convoluted way and I can’t seem to understand how existing Vue infrastructure, allowing ES6 imports gets wired to the Frappe instance.
This is what I’ve got for now:
new_page.js
:
frappe.provide('frappe.app.export_app');
frappe.pages['new_page'].refresh = function(wrapper) {
if (!$('#app').length) {
$(frappe.render_template('new_page_template', page)).prependTo(page.main);
}
frappe.require('assets/dc_plc/js/vue/button_counter.js', () => {
Vue.component('button_counter', button_counter());
frappe.app.export_app.vue_instance = new Vue({
el: '#app',
data: {}
});
});
};
button_counter.js
:
let button_counter = () => {
return {
data: function () {
return {
count: 0
}
},
name: 'button_counter',
template: '<button v-on:click="count++">Click counter — {{ count }}</button>'
}
};
new_page_template.html
:
<div id="export-app">
<button_counter></button_counter>
</div>