简体   繁体   English

Django + Vue3 + Vite

[英]Django + Vue3 + Vite

I am upgrading my multipage app from Vue2+webpack to Vue3+vite.我正在将我的多页应用程序从 Vue2+webpack 升级到 Vue3+vite。

I got to a point where I can see and render my vue3 on my django templates and all the setup seems to be working.我到了可以在我的 django 模板上看到和渲染我的 vue3 的地步,所有设置似乎都在工作。

Now I need to set some of the component variables on the vue app using the django template, but I can't get a hold of my vue instance to do so.现在我需要使用 django 模板在 vue 应用程序上设置一些组件变量,但我无法获取我的 vue 实例来执行此操作。

Before I use to do:在我使用之前:

//after window loads
app = document.getElementById('abc_app').__vue__ ;
app.message = "New Message";

And it would display the new message.它会显示新消息。

Now the same doesn't work anymore for vue3, and changing the code to __vue__app__ doesn't work either.现在同样对 vue3 不再起作用,将代码更改为__vue__app__也不起作用。

Entry JS from vue2:来自 vue2 的入口 JS:

import Vue from 'vue'
import abc_app from './abc_app.vue'

const root_element = document.getElementById('abc_app');
const AppRoot = Vue.extend(abc_app);
new AppRoot({
    el: root_element,
    propsData: { ...root_element.dataset }
 });

new entrypoint for Vue3 Vue3 的新入口点

import abc_app from './abc_app.vue'
const root_element = document.getElementById('abc_app');
import { createApp } from 'vue'
import { createPinia } from 'pinia'

const app = createApp(abc_app)

app.use(createPinia())

app.mount(root_element)

I was able to access the data elements (not the methods) with:我能够通过以下方式访问数据元素(不是方法):

app = document.getElementById('abc_app'). __vue__app__.instance;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM