前段時間終於終於能夠用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