Reputation: 6769
fil1.vue
<script setup>
import { ref } from 'vue'
const msg = ref('Hello World!')
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg">
</template>
I would like to render this in my Django template.
Previously with normal vue components I was able to do use them as follows:
JS file:
Vue.component('comp1', {...})
django html template:
<comp1> </comp1>
I was able to get App.vue mounted on django div element with id=app
-My github repo
id=app
in homepage.html
. Is there another way of rendering App.vue
in django homepage.html ?<HelloWorld>
directly in my django template ?If someone can provide a link to a public github repo that has used SFC with django that would be helpful.
Upvotes: 2
Views: 1534
Reputation: 1
Use customElements and defineCustomElement in this way
import { createApp } from 'vue'
import { defineCustomElement } from 'vue'
import App from './App.vue'
import AddListing from "./components/AddListing.vue";
import EditListing from "./components/EditListing.vue";
// Add Listing form
customElements.define('add-listing', defineCustomElement(AddListing))
customElements.define('edit-listing', defineCustomElement(EditListing))
const marketApp = createApp(App)
marketApp.mount('#app')
Then you will be able to use it outside of div#app by calling:
<add-listing />
or
<edit-listing />
Upvotes: 0
Reputation: 6769
Following is what I know so far. There may be a better solution out there.
id=app
and from there we can route users to different pages. Everything is done in Vue. No Django needed or used.Following is how I am using it currently:
Vue2.6
.component1.js
Vue.component('name-comp', {
props: {
},
data: function () {
return {
}
},
watch: {
},
mounted: async function () {
},
methods: {
},
template: `
`,
delimiters: ["[[", "]]"],
});
h1.html
<name-comp></name-comp>
<script type="text/javascript" src="{% static 'app1/js/component1.js'%}">
Upvotes: 1