zoukankan      html  css  js  c++  java
  • 关于第一次使用vuecli

    前段时间终于终于可以用vue-cli,webpack做个企业站,记一下过程。。。

    首先node.js,按照vue官网的步骤命令提示符走一波,网速原因,所以用的是淘宝镜像 cnpm

    # 全局安装 vue-cli
    $ npm install --global vue-cli
    # 创建一个基于 webpack 模板的新项目
    $ vue init webpack my-project
    # 安装依赖
    $ cd my-project
    $ npm install
    $ npm run dev
    然后安装需要用到的其它插件。
    安装axios npm install 要写入到package.json 里面 所以后面加上--save,其它安装一样,axios不能使用 Vue.use() 而是 Vue.prototype.$ajax = axios,使用this.$ajax.get(url).then(function(){res}) 
    jq npm安装的是最新版本的 想要使用2.1.4版本的,在json文件找到jq 然后改为自己想用的版本,npm install 重新走一遍。
    在webpack.base.conf.js里面配置jq,最上面加上 var webpack = require("webpack") 下面也要加上
      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可以使用了。

    router传参部分

    <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; 

    项目完成之后config-->index.js里面dev-->assetsPublicPath的'/'换成‘./’改变一下路径。 npm run build 上传服务器。

    生成不在根目录下的项目

    在改换路径里面配置

    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
      }
    }

     设置路由:

    {path:'*',redirect:'/index'}设置重定向
    

    封装组件:

     

  • 相关阅读:
    Ubuntu 32下Android NDK+NEON的配置过程及简单使用举例
    java环境变量配置
    实现TextView 文字排版,分散两端对齐
    cmd 控制台 提示:请求的操作须要提升!
    怎样将程序猿写出来的程序打包成安装包(最简单的)
    二分查找
    32位Linux文件限制大小
    Windows ICS 服务无法启动问题解决
    Microsoft.AlphaImageLoader滤镜解说
    memset函数具体说明
  • 原文地址:https://www.cnblogs.com/vipp/p/7244966.html
Copyright © 2011-2022 走看看