Vue疑难杂症

本文详细介绍了Vue项目从安装脚手架到打包部署的全过程,包括解决安装过程中的警告和错误,使用cnpm和淘宝镜像加速依赖包下载,以及如何正确配置和运行webpack进行项目打包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装Vue脚手架的时候

指令:npm install vue-cli -g

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>npm install vue-cli -g
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coff
eescript" (no hyphen)
C:\Users\Administrator\AppData\Roaming\npm\vue -> C:\Users\Administrator\AppData
\Roaming\npm\node_modules\vue-cli\bin\vue
C:\Users\Administrator\AppData\Roaming\npm\vue-init -> C:\Users\Administrator\Ap
pData\Roaming\npm\node_modules\vue-cli\bin\vue-init
C:\Users\Administrator\AppData\Roaming\npm\vue-list -> C:\Users\Administrator\Ap
pData\Roaming\npm\node_modules\vue-cli\bin\vue-list
+ vue-cli@2.9.6
added 4 packages from 1 contributor, removed 389 packages and updated 235 packag
es in 251.71s

C:\Users\Administrator>

报了一个警告:如下

        npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

解决办法(说明):coffee-script 这个依赖包xx的改名了,不影响你使用的,还有coffee-script已经过气了:)

 

初始化Vue项目的时候

vue init webpack test-2vlft

G:\sinoyd\personalProject>vue init webpack test-2vlft

? Project name test-2vlft
? Project description A Vue.js project
? Author xichaoqun <1593760568@qq.com>
? Vue build (Use arrow keys)
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recom
? Should we run `npm install` for you after the project has been created? (recom

mended) npm

   vue-cli · Generated "test-2vlft".


# Installing project dependencies ...
# ========================

npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and n
ew features!
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Br
owserslist >3.0 config used in other tools.
npm ERR! Unexpected end of JSON input while parsing near '...1PMB+NX2XCrirPUJC2m
A6'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-04-20T0
5_10_15_943Z-debug.log

# Project initialization finished!
# ========================

To get started:

  cd test-2vlft
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack

   警告+错误:

npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and new features!
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm ERR! Unexpected end of JSON input while parsing near '...1PMB+NX2XCrirPUJC2mA6'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-04-20T05_10_15_943Z-debug.log
解决办法:
解决办法:
cnpm install (在安装淘宝镜像的前提下  npm install -g cnpm --registry=https://registry.npm.taobao.org    cmd切入项目的所在目录,执行cnpm install)
例子:  G:\sinoyd\personalProject\test-2vlft>cnpm install
安装Vue脚手架的时候

Vue项目打包
首先要 cnpm 下载 webpack

cmd 执行以下命令
cnpm install webpack -g
cnpm install webpack-cli -g

最后输入 webpack -v 弹出版本 表示安装成功

cmd 输入 cnpm install webpack -g  会报错

[fsevents@^1.2.7] optional install error: Package require os(darwin) not compati
ble with your platform(win32)

大致意思:这是一个可以忽略的错误,fsevents是可选的依赖,只能应用于maxOS系统,不适合Windows或者Linux,也就是忽略即可。

打包过程:先停止该Vue项目,cmd 输入 npm run build 等待,即打包完成

 

 

转载于:https://www.cnblogs.com/yingyigongzi/p/10740639.html

### ElementUI 使用过程中的常见疑难问题及解决方案 #### el-input 无法输入的问题 在开发 Vue 应用时,`el-input` 组件有时会遇到无法正常输入的情况[^1]。这通常不是由于明显的错误引起,而是由一些细微之处造成的。 - **双向绑定问题**:如果 `v-model` 的数据源被意外覆盖或未正确初始化,则可能导致输入框失去响应能力。 - **禁用状态误设**:检查是否有无意间设置了 `disabled` 属性给 `el-input` 或其父级容器,从而阻止了用户的交互操作。 - **只读属性影响**:确认是否不小心启用了 `readonly` 特性,使得用户虽然能看到光标却不能修改内容。 为了诊断此类问题,建议逐步移除可能干扰的因素,并利用浏览器开发者工具监控 DOM 和事件监听器的变化情况来定位具体原因。 ```html <template> <div> <!-- 确认 v-model 是否正确 --> <el-input v-model="message"></el-input> </div> </template> <script> export default { data() { return { message: '' }; } }; </script> ``` #### element-ui 引入 index.css 报错 (No PostCSS Config found) 当项目中尝试加载 Element UI 提供的基础样式文件 `index.css` 而遭遇 "No PostCSS Config found" 错误提示时,表明缺少必要的构建配置项[^2]。 解决办法是在项目的根目录下创建 `.postcssrc.js` 文件,并添加如下所示的基本设置: ```javascript module.exports = { plugins: [ require('autoprefixer') ] } ``` 此外,还需确保安装了相应的依赖包如 `autoprefixer` 和 `postcss-loader` 来支持 CSS 预处理功能。 #### scoped 样式的实现机制及其注意事项 带有 `scoped` 关键字的 `<style>` 标签能够限定样式的应用范围仅限于当前组件内部[^3]。这种特性通过向 HTML 元素动态附加唯一标识符的方式达成目的——即为每一个受保护的选择器追加特定的数据属性作为过滤条件。 然而,在某些情况下,特别是涉及到插槽(slot)传递的内容或是第三方库提供的组件时,可能会出现预期之外的行为。因此对于这些特殊情况下的样式定制应当格外小心谨慎。 #### history 模式路由部署需注意的服务端配合事项 采用 History API 实现前端页面跳转的应用程序,在生产环境中部署时需要注意服务端如何适配 URL 请求路径[^4]。如果不做任何额外设定,默认情况下服务器只会识别静态资源请求而忽略掉那些实际上应该交给客户端解析的历史记录地址。 为了避免由此引发的一系列兼容性和显示异常(比如空白页),推荐的做法是让 Web Server 对所有非资源类别的 GET 请求统一返回入口HTML文档(通常是 `index.html`)。这样即使刷新页面也能保持正常的浏览体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值