• Vue创建项目入门


    Vue创建项目入门

    步骤

    • 修改main.js,引入axios和element-ui
    • 自己创建vue.config.js
    • npm i element-ui -S
    • npm i axios -S

    main.js

    import Vue from 'vue'
    import App from './App.vue'
    import './plugins/element.js'
    
    import axios from 'axios'
     //将axios挂载在Vue扩展上
     Vue.prototype.$http=axios
     //在其他地方使用只需使用 this.$http来代替axios;
     //配置baseUrl
    axios.defaults.baseURL = '/api'
    
    
    Vue.config.productionTip = false
    
    new Vue({
      render: h => h(App),
    }).$mount('#app')
    

    vue.config.js

    module.exports = {
        devServer: {
     	    // 设置主机地址
            host: 'localhost',
            // 设置默认端口
            port: 51001,
            // 设置代理
            // proxy: {
            //     'douban': {
            //         // 目标 API 地址
            //         target: 'http://douban',
            //         // 如果要代理 websockets
            //         ws: true,
            //         // 将主机标头的原点更改为目标URL
            //         changeOrigin: false
            //     }
            // }
            proxy: {
                '/api': {
                  target: 'http://localhost:52001/api',
                  changeOrigin: true,
                  pathRewrite: {
                    '^/api': ''
                  }
                }
              }
        }
    }
    

    编写页面请求后台接口

    <template>
    <div>
      <div @click="queryStudentList()">学成</div>
    </div>
    </template>
    
    <script>
    export default {
      name: 'HelloWorld',
      props: {
        msg: String
      },
      data() {
          return {}
        },
        methods: {
          queryStudentList(){
            this.$http("/user/list")
            .then(function(res){
              console.log(res);
            })
          }
        }
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style>
    </style>
    
  • 相关阅读:
    hive创建ES外部表过程中的问题
    Hive 与 ElasticSearch 的数据类型对照
    ambari启动hive服务失败
    calcite 1.22新特性
    自动化打包工具gulp
    js中数组的用法
    JavaScript的基础语法
    node.js初体验
    函数的执行过程和闭包
    Ajax -Asynchronous Javascript And XML(异步 JavaScript 和 XML)
  • 原文地址:https://www.cnblogs.com/mozq/p/12316036.html
Copyright © 2020-2023  润新知