前段时间终于终于能够用vue-cli,webpack作个企业站,记一下过程。。。javascript
首先node.js,按照vue官网的步骤命令提示符走一波,网速缘由,因此用的是淘宝镜像 cnpmcss
resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'jquery': 'jquery' } }, // 增长一个plugins plugins: [ new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery" }) ],
自此jq能够使用了。html
router传参部分vue
<router-link :to="{path:'/Hello',query: {Id: item.Id,category:3}}"> <img v-bind:src="item.Img" /> <span v-text="item.Title"></span> </router-link>
接收参数 this.$route.query.Id this.$route.query.category; java
项目完成以后config-->index.js里面dev-->assetsPublicPath的'/'换成‘./’改变一下路径。 npm run build 上传服务器。node
生成不在根目录下的项目jquery
在改换路径里面配置webpack
module.exports = { build: { env: require('./prod.env'), index: path.resolve(__dirname, '../dist/ceshi/index.html'), assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'ceshi/static', assetsPublicPath: '/', productionSourceMap: false, // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report }, dev: { env: require('./dev.env'), port: process.env.PORT || 8080, autoOpenBrowser: true, assetsSubDirectory: 'ceshi/static', assetsPublicPath: './', proxyTable: {}, // CSS Sourcemaps off by default because relative paths are "buggy" // with this option, according to the CSS-Loader README // (https://github.com/webpack/css-loader#sourcemaps) // In our experience, they generally work as expected, // just be aware of this issue when enabling this option. cssSourceMap: false } }
设置路由:ios
{path:'*',redirect:'/index'}设置重定向
封装组件:git