我是靠谱客的博主 调皮水壶,这篇文章主要介绍IntelliJ IDEA在使用Thymeleaf时用axios拦截get请求发送post请求没有效果,现在分享给大家,希望可以做个参考。

在写SpringMVC时,使用Thymeleaf解析资源路径,使用了vue和axios,发现无论怎么改代码都是无法发送POST请求
解决办法:在导入vue和axios时一定要写

 <script type="text/javascript" th:src="@{/static/js/vue.min.js}">
 </script>这种方式才是正确的如果
<script type="text/javascript" th:src="@{/static/js/vue.min.js}"/>
这么写是错误的

下面是正确的

<div id="app">
    <a @click="put1" th:href="@{/axios}">update</a>
  </div>

  <script type="text/javascript" th:src="@{/static/js/vue.min.js}"></script>
  <script type="text/javascript" th:src="@{/static/js/axios.js}"></script>
  <script>
    new Vue({
      el:"#app",
      methods: {
        put1: function (event) {
          axios({
            method: "post",
            url: event.target.href,
            params: {
              name: "abc",
              password: "123"
            }
          }).then(function (response) {
            alert(response.data);
          });
          event.preventDefault();
        }
      }
    });
  </script>

最后

以上就是调皮水壶最近收集整理的关于IntelliJ IDEA在使用Thymeleaf时用axios拦截get请求发送post请求没有效果的全部内容,更多相关IntelliJ内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部