简体   繁体   English

如何使用简单的“a”标签在现有网站中包含使用 npm 和 webpack 构建的 vuejs 应用程序?

[英]how to include a vuejs app build with npm and webpack in an existing website with a simple 'a' tag?

i am building a small web app, i have used vue.js router,npm,webpack and all to build like a single page web app.我正在构建一个小型 Web 应用程序,我使用了 vue.js 路由器、npm、webpack 和所有这些来构建一个单页 Web 应用程序。 now i want to include it to my existing website by just adding a new navigation menu tab with the app name, by clicking on the tab it has to open my app.现在我想将它包含到我现有的网站中,只需添加一个带有应用程序名称的新导航菜单选项卡,单击它必须打开我的应用程序的选项卡。 like a tab in website how can i do this?就像网站上的标签一样,我该怎么做? i really like webpack workflow.我真的很喜欢 webpack 工作流程。 i dont want to build the app into my website using normal vue method.我不想使用普通的 vue 方法将应用程序构建到我的网站中。 can i combine my app and website by include an app tab in my website?我可以通过在我的网站中包含一个应用程序选项卡来组合我的应用程序和网站吗?

I'm making the assumption that the rest of your site is not using Vue and that you want to make it so that when you click on 'Vue App' in the nav you want the contents of that page to be a Vue app.我假设您网站的其余部分没有使用 Vue,并且您希望这样做,以便当您在导航中单击“Vue 应用程序”时,您希望该页面的内容成为 Vue 应用程序。

Yes you can do this, just include your script on the page you want to make use vue.是的,您可以这样做,只需在您要使用 vue 的页面上包含您的脚本。 You should be able to do this by following https://v2.vuejs.org/v2/guide/index.html .您应该可以按照https://v2.vuejs.org/v2/guide/index.html执行此操作。

File VueApp.html文件 VueApp.html

<div id="myApp">
  <span v-bind:title="message">
    Hover your mouse over me for a few seconds
    to see my dynamically bound title!
  </span>
</div>
<script src="app.min.js"></script> // Your compiled file from webpack

myApp.js (include this file in webpack) myApp.js(在 webpack 中包含这个文件)

var app2 = new Vue({
    el: '#myApp', 
    data: {
     message: 'You loaded this page on ' + new Date().toLocaleString()
    }
})

Vue doesn't really care where it's implemented, when it comes down to it it's just javascript. Vue 并不真正关心它在哪里实现,归根结底它只是 javascript。 Where you will run into trouble is when you try and implement it several times on the same page.当您尝试在同一页面上多次实施它时,您会遇到麻烦。

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

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