[英]Using Vue.js in a standalone project
I am trying to learn Vue.js for work, and I seem to have the syntax down, but I have a question about creating an overall project.我正在尝试学习 Vue.js 以供工作,我的语法似乎有所下降,但我有一个关于创建整体项目的问题。
So far, to create a project, I have had to use npm to create the project (or start the ui, and do it from there).到目前为止,要创建一个项目,我必须使用 npm 来创建项目(或启动 ui,然后从那里开始)。
But I am wondering how I can include Vue without always running serve via command prompt to render it in my browser.但我想知道如何在不总是通过命令提示符运行服务的情况下包含 Vue 以在我的浏览器中呈现它。 For example, if I am creating a website front end with html, css, and some javascript, can I somehow import Vue to that and use it?
例如,如果我正在使用 html、css 和一些 javascript 创建网站前端,我可以以某种方式将 Vue 导入并使用它吗?
I assume with something like this:我假设这样的事情:
<script src="https://unpkg.com/vue-multiselect@2.1.0"></script>
I think this link will help you.我认为这个链接会对你有所帮助。
https://v2.vuejs.org/v2/guide/#Getting-Started https://v2.vuejs.org/v2/guide/#Getting-Started
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script>
</head>
<body>
<div id="app">
<p>{{ message }}</p>
</div>
<script src="index.js"></script>
</body>
</html>
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!'
}
})
But if you have a .vue files like this:但是如果你有这样的.vue文件:
<template>
<!- ... ->
</template>
<script>
// ...
</script>
You don't have the choice, you need to run the script npm run serve
or yarn serve
for compiling the .vue file into a valid javascript file.您别无选择,您需要运行脚本
npm run serve
或yarn serve
来将.vue文件编译成有效的 javascript 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.