vue.js - 如何在没有 npm 的情况下运行项目
问题描述
我正在使用 Vue.js
我想使用树形数据结构https://github.com/vinz3872/vuejs-tree
如果您使用 npm,这将非常有用。但我不想使用 npm。我想使用从 CDN 导入。但是当我从 CDN 导入时,我无法让它工作。我不知道该怎么做。
我尝试过不同的方式。我从 vuejs-tree/dist 包中取出文件并将它们放入项目中,它仍然无法正常工作。
在我看来,我做错了什么。您能告诉我如何通过从 CDN 导入 HTML 页面来使其工作吗?不是 npm 安装。
下面我展示了一个使用 npm 构建项目的示例。我需要把它翻译成一个没有 npm 的项目。
main.js
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
应用程序.vue
<template>
<div>
<Tree
id="my-tree-id"
ref="my-tree"
:custom-options="myCustomOptions"
:custom-styles="myCustomStyles"
:nodes="treeDisplayData"
></Tree>
</div>
</template>
<script>
import Tree from "vuejs-tree";
export default {
name: "App",
components: {
'Tree': Tree
},
data () {
return {
treeDisplayData: [
{
id: 1,
text: "Electronics",
state: { checked: true, selected: true, expanded: true },
checkable: false,
depth: 3,
nodes: [],
}
],
};
},
computed: {
myCustomStyles() {
return {
};
},
myCustomOptions() {
return {
};
},
},
mounted() {
this.$refs["my-tree"].expandNode(1);
},
methods: {
myCheckedFunction: function (nodeId, state) {
},
mySelectedFunction: function (nodeId, state) {
},
deleteNodeFunction: function (node) {
},
addNodeFunction: function (node) {
},
},
};
</script>
<style scoped>
</style>
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Tree structure</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
https://v3.vuejs.org/guide/installation.html
1.在页面导入为CDN包
下载 JavaScript 文件并自行托管
使用 npm 安装它
使用官方 CLI 搭建一个项目,该项目为现代前端工作流程提供包含电池的构建设置(例如,热重载、lint-on-save 等等)
我想使用选项 1
我导入了所有必需的包,但它不起作用。
解决方案
推荐阅读
- java - 无法访问android 11中的文件
- java - Java 是否将内存分配给没有给定值的对象变量?
- xgboost - 如何以 .pd 格式而不是 json 保存和加载 XGboost 分类器模型?
- python - 我有一个以下格式的字符串。如何在 python 中找到索引的内容?
- android-studio - Android Studio 2020.3.1 无法登录github
- mongodb - 如何通过聚合将 MongoDB 文档转换为树结构?
- ios - 使用有效内容剪辑 UIImage
- python - 如何在 jupyter notebook 上的 vscode 上运行 kaggle 数据集?
- c++ - 调整形式为 v[N] 的多维向量的大小
- json - Powershell自定义对象到Json