0
点赞
收藏
分享

微信扫一扫

Spring Cloud Alibaba 架构-Sentinel

探头的新芽 2024-05-24 阅读 30

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue Element UI POST Request</title>
    <link
      rel="stylesheet"
      href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
    />
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  </head>
  <body>
    <div id="app" style="text-align: center; margin-top: 20%">
      <el-button type="primary" @click="sendPostRequest">
        Send POST Request
      </el-button>
    </div>

    <script>
      new Vue({
        el: '#app',
        data: function () {
          return {}
        },
        created() {
          // this.sendConcurrentRequests()
        },

        methods: {
          sendPostRequest() {
            axios
              .post('', {
                password: '',
                username: ''
              })
              .then(response => {
                console.log(response.data)
                this.$message.success(`successful==>>【${response.data.data}】`)
              })
              .catch(error => {
                console.error('There was an error!', error)
                this.$message.error('POST request failed!')
              })
          },

          sendConcurrentRequests() {
            const requests = []
            for (let index = 0; index < 1000; index++) {
              requests.push(this.sendPostRequest())
            }
            Promise.all(requests)
              .then(responses => {
                responses.forEach(response => {
                  console.log(response.data)
                })
                this.$message.success('All requests were successful!')
              })
              .catch(error => {
                console.error('There was an error!', error)
                this.$message.error('Some requests failed!')
              })
          }
        }
      })
    </script>
  </body>
</html>
举报

相关推荐

0 条评论