我刚刚开始使用VueJS,目前我正在尝试使用Webpack-Loader将它添加到我的Django项目中。
我有以下两个文件:
App.vue
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your first Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'app',
components: {
HelloWorld
}
}
</script>App02.vue
<template>
<div id="app02">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your second Vue.js App0"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'app02',
components: {
HelloWorld
}
}
</script>
<style>
#app02 {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>这是我的main.js
import Vue from "vue/dist/vue.js";
import Vuex from "vuex";
import storePlugin from "./vuex/vuex_store_as_plugin";
import App from './App.vue'
Vue.use(Vuex);
Vue.use(storePlugin);
Vue.config.productionTip = false;
/* NOTE: unlike index.js, we are not passing props from our template, so the following render/mount
syntax is ok */
new Vue({
render: h => h(App),
}).$mount('#app');最后,这里是我的Django html模板:
{% load render_bundle from webpack_loader %}
{% block content %}
<h3>My second Vue app goes here</h3>
<div id="app">
<app></app>
</div>
{% render_bundle 'chunk-vendors' %}
{% render_bundle 'vue_app_02' %}
{% endblock %}我的代码的问题是它似乎没有加载App02,因为当我加载html时,我会看到欢迎进入您的第一个Vue应用程序,而不是欢迎到您的第二个应用程序,尽管从我的模板中,我正在加载vue_app_02。
我知道这个问题是非常基本的,但我对此非常陌生,而且一切都很混乱,我不明白我需要什么main.js和其他文件,如index.js、index.html。任何建议都会受到赞赏。
发布于 2020-12-19 15:46:33
必须将app02.vue添加到vue路由器中。
此站点可以帮助您创建vue路由器。
https://saidhayani.medium.com/understand-routing-in-vue-js-with-examples-6da96979c8e3
https://stackoverflow.com/questions/65371320
复制相似问题