VUE:常见脚本及错误

本文详细介绍了如何在Node.js环境中进行npm配置,如设置全局模块路径、淘宝镜像源、清理缓存,以及在VueCLI项目中初始化、安装依赖、处理axios请求、解决CSS编译问题和引入VueCookies。

查看node安装信息

npm config list

设置全局模块安装路径

npm config set prefix "D:\java\node\node_global"

设置缓存目录

npm config set cache "D:\java\node\node_cache"

设置镜像源为淘宝npm镜像

npm config set registry=https://registry.npm.taobao.org

1.项目初始化

vue init webpack ui

2.安装脚手架

npm install webpack -g
npm install webpack-cli -g
npm install -g @vue/cli

        指定版本:

npm install -g @vue/cli@4.5.6

3.镜像

(1)查看

npm config get registry

(2)设置

npm config set registry https://registry.npm.taobao.org

清除缓存

npm cache clean --force

npm install --save axios

npm install axios@1.5.0 --save

npm i element-ui -S
npm i echarts

 111.npm ERR! request to https://registry.npm.taobao.org/@vue%2fcli failed, reason: certificate has expired

npm config set strict-ssl false

import导入带有@路径,鼠标无法点击进入,在根目录下新建如下文件:

jsconfig.json
{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@/*": [
                "src/*"
            ]
        },
        "target": "ES6",
        "allowSyntheticDefaultImports": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

axios使用post传参,但是参数还是挂在url后面,原因是传参方式不对

params是参数拼接在url上:

data是对象形式:

安装css:saas

node版本是16.18.1

npm install node-sass@6.0.1 sass-loader@10.2.0 --save-dev
npm install -g node-gyp
npm install --global --production windows-build-tools

引入cookie

npm install vue-cookies --save

main.js引入

import VueCookies from 'vue-cookies'
Vue.use(VueCookies)

Vue 中使用 Qunee 时,出现 `TypeError: graph.setStyle is not a function` 的问题,通常是因为 `graph` 实例未正确初始化或未正确引入 Qunee 的相关模块。Qunee 提供了丰富的图形组件和 API,但在 Vue 等现代前端框架中使用时,需要注意模块加载和实例化方式。 在 Vue 项目中初始化 Qunee 图形组件时,应确保正确引用 Qunee 的 JavaScript 库,并在 `mounted` 生命周期钩子中创建 `Qunee.Graph` 实例。如果 `graph` 变量未正确指向 Qunee 的图形实例,调用 `setStyle` 方法时就会报错。 ### 修正 initGraph 方法 确保在 `mounted` 钩子中正确初始化 `graph` 实例,并将其挂载到 Vue 组件的 `data` 中,以便在其他方法中调用: ```javascript export default { name: 'QuneeTopology', data() { return { graph: null }; }, mounted() { this.initGraph(); }, methods: { initGraph() { const container = document.getElementById('graph-container'); this.graph = new Qunee.Graph(container); // 设置节点悬停时的光标样式 this.graph.setStyle(Qunee.Styles.NODE_CURSOR, "pointer"); } } }; ``` ### 常见错误原因 1. **未正确加载 Qunee 库** 如果未在组件中正确导入 Qunee 的 JS 库,可能导致 `Qunee` 对象未定义,从而无法创建 `Graph` 实例。应确保在 `index.html` 或通过 `import` 正确引入 Qunee 脚本: ```html <script src="https://unpkg.com/qunee/umd/Qunee.js"></script> ``` 2. **使用错误的命名空间或 API** Qunee 的 `setStyle` 方法属于 `Graph` 实例,而非全局对象或其他组件。如果 `graph` 指向了错误的对象(如 `null` 或非 `Graph` 实例),则会报错。确保 `this.graph` 是 `Qunee.Graph` 的实例。 3. **异步加载未完成** 如果 Qunee 库是异步加载的,而 `initGraph` 在库加载完成前被调用,也会导致 `setStyle` 不可用。应使用 `onload` 回调或 `Promise` 确保脚本加载完成后再初始化图形。 ### 示例代码 以下是一个完整的 Vue 组件示例,确保 Qunee 正确加载并初始化: ```vue <template> <div id="graph-container" style="width: 100%; height: 600px;"></div> </template> <script> export default { name: 'QuneeTopology', data() { return { graph: null }; }, mounted() { this.loadQuneeScript().then(() => { this.initGraph(); }); }, methods: { loadQuneeScript() { return new Promise((resolve, reject) => { const script = document.createElement('script'); script.src = 'https://unpkg.com/qunee/umd/Qunee.js'; script.onload = resolve; script.onerror = reject; document.head.appendChild(script); }); }, initGraph() { const container = document.getElementById('graph-container'); this.graph = new Qunee.Graph(container); // 设置节点悬停时的光标样式 this.graph.setStyle(Qunee.Styles.NODE_CURSOR, "pointer"); } } }; </script> ``` 通过上述方式,可以有效解决 `graph.setStyle is not a function` 的问题,并确保 Qunee 在 Vue 项目中正常运行[^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值