小编Clu*_*nce的帖子

Vue JS 在 console.log 上返回 [Object object] 并在 JSON.parse 上返回未定义

所以我正在编写这个 Vue.JS 代码来显示 PHP 从服务器获取的数据。PHP 将 JSON 对象返回给 Vue,VUE 必须显示它。我当前的代码是:

  axiosPost();
}
function axiosPost()
{
 axios.post(
  './ConversationGetter.php',
  {
    function2call: 'getRecord',
    id: 1,
    access: this.accesstoken
  }

)
.then(response =>  {this.data=response.data;
console.log(response.data);
console.log("Response From VUE JS"+this.data);

})
.catch(error => {});
}
Run Code Online (Sandbox Code Playgroud)

问题是,首先console.log正确打印响应数据。但第二个console.log显示这个:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Run Code Online (Sandbox Code Playgroud)

如果我在显示数据时使用 JSON.parse,它会显示以下内容:

undefined
Run Code Online (Sandbox Code Playgroud)

javascript php json vue.js axios

4
推荐指数
1
解决办法
7033
查看次数

如何阻止从浏览器控制台访问 Firebase 实时数据库?

我有这个 JavaScript 代码,用户可以使用他们的 Google 帐户登录我的应用程序。

//firebase db congifurations
const config = {
  apiKey: "my_api_key",
  authDomain: "my-app.firebaseapp.com",
  projectId: "my-app",
  databaseURL: "https://my-app.firebaseio.com",
};

//signin callback implemented using - https://developers.google.com/identity/sign-in/web/sign-in
function onSignIn(googleUser) {
  var profile = googleUser.getBasicProfile();

  let fullName = profile.getName().split(" "); 
  let userName = profile.getEmail().replace(/@.*$/, "");

  if (!firebase.apps.length) {
    firebase.initializeApp(config);
  }
  this.database = firebase.database();

  let userRef = this.database.ref("users/" + userName);
  userRef.set({
    firstName: fullName[0],
    lastName: fullName[1],
    displayPicture: profile.getImageUrl(),
  });
}

Run Code Online (Sandbox Code Playgroud)

当我执行此代码时,放置一个调试器let userRef = this.database.ref("users/" + userName);并尝试在控制台上运行它:

 userRef.set({
    firstName: "Clutch",
    lastName: "Prince", …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-authentication firebase-realtime-database

2
推荐指数
1
解决办法
1101
查看次数

Javascript使用优先级数组对对象数组进行排序

我有这个对象数组:

var eventList = [
    {
        eventName: "abc",
        status: "completed"
    },
    {
        eventName: "def",
        status: "live"
    },
    {
        eventName: "ghi",
        status: "live"
    },
    {
        eventName: "jkl",
        status: "upcoming"
    },
]
Run Code Online (Sandbox Code Playgroud)

我想使用特定键的优先级数组对这些对象数组进行排序,例如["live", "upcoming", "completed"]状态,这意味着所有实时事件首先出现,然后是即将发生的事件,然后是已完成的事件。互联网上的答案似乎只能使用键按升序或降序对数组对象进行排序。我该如何处理?

javascript arrays sorting object node.js

2
推荐指数
1
解决办法
113
查看次数

从 Vue.JS 中的外部文件读取和显示 JSON 数据

我有这个 View.JS 应用程序,我目前正在其中显示来自 JSON 的对话线程。目前的代码如下所示:

const app = new Vue({
  el: "#app",
  data: {
      messages:[
      {
      name: "Support",
      message: "Hey! Welcome to support"
      },
      {
      name: "Me",
      message: "Hello there!"
      },
      {
      name: "Support",
      message: "What can I do for you?"
      }
],
  },
  template: `
    <div>
      <p v-for="message in messages"><b>Name: </b>{{message.name}} </br><b>Message: </b>{{message.message}}</br></p>
    </div>
  `
})
Run Code Online (Sandbox Code Playgroud)

现在我想将这些数据保存在外部 JSON 文件(在同一目录中称为“data.json”)并具有相同的输出。关于我如何做到这一点的任何想法?

html javascript json vue.js vuejs2

-1
推荐指数
1
解决办法
3404
查看次数