程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容?

开发过程中遇到Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容的问题如何解决?下面主要结合日常开发的经验,给出你关于Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容的解决方法建议,希望对你解决Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容有所启发或帮助;

我的帖子请求工作正常,但在我执行硬刷新之前在页面上看不到任何内容。我会感谢任何人对我应该做的事情的看法。我已经被这个问题困住了一段时间。我是 Vue3 的新手。

我在哪里获取 API 数据:

created() {
    fetch(BASE_URL + "revIEws")
      .then((res) => res.Json())
      .then((results) => {
        this.revIEws = results;
      });
  },

我的发帖方式:

  methods: {
    addRevIEw() {
      console.log(this.revIEw);
      fetch(BASE_URL + "revIEws",{
        method: "POST",body: JsON.Stringify(this.revIEw),headers: {
          "content-type": "application/Json",},})
        .then((res) => res.Json())
        .then((result) => {
          if (result.details) {
            const error = result.details
              .map((detail) => detail.messagE)
              .join(".");
            this.error = error;
          } else {
            this.error = "";
            this.revIEws.push(result);
          }
        });
    },

解决方法

<script>
import Navbar from "./Navbar";
import Footer from "./Footer";
const BASE_URL = "https://gearsbeans-api.herokuapp.com/";
// const BASE_URL = "http://localhost:3001/";
export default {
  name: "Reviews",components: {
    Navbar,Footer,},data: () => ({
    error: "",reviews: [],review: {
      name: "",message: "",product: "",stars: 0,about: "check out our reviews",}),computed: {
    reversedReviews() {
      return this.reviews.slice().reverse();
    },methods: {
    getReviews: async function() {
      const response = await fetch(BASE_URL + "reviews");
      const data = await response.json();
      this.reviews = data;
    },addReview: async function() {
      await fetch(BASE_URL + "reviews",{
        method: "post",headers: {
          "Content-Type": "application/json",body: JSON.Stringify({
          name: this.review.name,message: this.review.message,product: this.review.product,stars: this.review.stars,});
      (this.review.name = ""),(this.review.message = ""),(this.review.product = ""),(this.review.stars = null);
      this.getReviews();
    },async deleteReview(id) {
      await fetch(BASE_URL + `reviews/${iD}`,{
        method: "deletE",headers: {
          "content-type": "application/json",this.getReviews();
    },created: function() {
    this.getReviews();
  },};
</script>

大佬总结

以上是大佬教程为你收集整理的Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容全部内容,希望文章能够帮你解决Vue 3 发布请求正在运行,但在重新加载页面之前不显示任何内容所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:3