New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom manager field with external vue component: Failed to mount component: template or render function not defined. #1279
Comments
Hi there @CSorel-Catalyte. First I have to ask about your resource setup. You say you are adding things into The correct way to add custom javascript in projects is to add resources into the manager using this approach: https://piranhacms.org/docs/manager-extensions/resources Best regards |
Thank you! Loading the external component as a resource doesn't change the result. The issue still exists. To be clear, we are working on a modified fork of the manager, but the modifications are limited to adding additional field types. We have followed the model that the current source uses (see date-field.vue as an example of one of your components using an external vue component.) We have added one field type for select boxes populated from an external source. That component template used html elements and does not have any child vue components. It works perfectly following the model your core field types use. In the case of this field type, we want to leverage an existing open source vue component to support our UX intentions. I have tried multiple vue components with the same result, so it seems to me that your current implementation of the manager doesn't support including child vue components sourced from npm, but I want to make sure that I have approached this correctly. I understand that you can't be responsible for branches outside of your control and I'm not expecting you to spend a lot of time supporting this but I am hoping that you provide the minimal effort to support us of looking at the code snippets above and offering your expert opinion as to whether we have approached it correctly. It also strikes me that it's worth you investigating to see if there is an issue, and if so you may want to add to your backlog as we will not be the only ones with this use case. |
I saw I misread your initial comment so I deleted my comment 😉 I’m not sure how the vue compilation works with locally included components as everything in the manager relies on globally registered components. The compilation of .vue files is handled in gulpfile.js and was submitted as a contribution, so I haven’t looked at it detail to see exactly what it handles and what it doesn’t. Regarding branching the manager, everything you’re doing can be done without branching it which will enable you to get access to new functionality easier. Regards |
And btw, version 8.4 will include a SelectField which can be populated from an external data source! #1186 |
HI @CSorel-Catalyte . Were you able to find a solution or workaround for this problem? I'm also trying to use vue components sourced from npm, with no luck. To make things even more complex, I'm new to vue :( |
@filipjansson I know the @horacioj As a starter, the manager is not a Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
}) Components defined this way are registered globally in Vue and can be referenced anywhere. For example, the file <template>
<textarea class="form-control" rows="4" :placeholder="meta.placeholder" v-model="model.value" v-on:change="update()"></textarea>
</template>
<script>
export default {
props: ["uid", "model", "meta"],
methods: {
update: function () {
// Tell parent that title has been updated
if (this.meta.notifyChange) {
var title = this.model.value;
if (title.length > 40) {
title = title.substring(0, 40) + "...";
}
this.$emit('update-title', {
uid: this.uid,
title: title
});
}
}
}
}
</script> Will be compiled into this by our build pipeline: Vue.component("text-field", {
props: ["uid", "model", "meta"],
methods: {
update: function () {
// Tell parent that title has been updated
if (this.meta.notifyChange) {
var title = this.model.value;
if (title.length > 40) {
title = title.substring(0, 40) + "...";
}
this.$emit('update-title', {
uid: this.uid,
title: title
});
}
}
},
template: "\n<textarea class=\"form-control\" rows=\"4\" :placeholder=\"meta.placeholder\" v-model=\"model.value\" v-on:change=\"update()\"></textarea>\n"
}); All of this happens in our Best regards |
Thank you, @tidyui. Yes, I was able to create a custom "hello world" vue component for a "hello world" block, a custom gulpfile,js to compile it, etc. What I wasn't able to do is to reuse external vue components. Is there a repo I can see where something like this (integrate external vue components) was implemented? E,g,. is there a repo I can access where the Many thanks! |
The vue component for the date field can be found here in the project |
We have not been able to use any 3rd party (i.e. npm) vue components. The only thing we have been successful with is writing our own components from scratch using an existing component as a template. |
It looks like it depends on how the 3rd party component was built. In case of the |
@horacioj Yes, I think you are right, I have come to the same conclusion when I have been looking at 3rd party components. I believe you could use many components that are built for the browser to work, it´s just a matter of how to add/activate/import it. |
I found a way to use any 3rd party prebuilt Vue component as global. As a plus the compilation of JS and SCSS resources is very simple, and it doesn't need any gulp. Just a few lines in a webpack.mix.js file. Ref.: https://laravel-mix.com/ : "Laravel Mix: An elegant wrapper around Webpack for the 80% use case." In my module project (where customs blocks, fields, etc. are implemented):
package.json
webpack.mix.js
mymodule.js
That's it. Simple, clean and easy. HTH, |
We are creating a custom field to be rendered in the manager as a double select box using this component: https://github.com/juliorosseti/vue-select-sides
The field class is defined as:
The region is implemented as:
The region is included in the page model as:
In Piranha.Manager, the select sides component is included in the gulp file as:
The custom-select component vue file is:
The component is included in the gulp compile as:
Everything builds and compiles correctly, but when I run manager and go to a page the field label is shown on the settings modal, but the component is not.
Looking in the console, I see:
I have confirmed that the select sides component is included in the piranha-deps.js (and piranha-deps-dev.js)
The compiled code in piranha.contentedit.min.js is:
Am I missing a step?
The text was updated successfully, but these errors were encountered: