manniru
7/3/2018 - 6:41 AM

Vue1

<div id="app">
  {{ message }}
</div>


<!-- Accent-colored raised button with ripple -->
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
  Button
</button>
const postData = (url = ``, data = {}) => {
  // Default options are marked with *
    return fetch(url, {
        method: "POST", // *GET, POST, PUT, DELETE, etc.
        mode: "cors", // no-cors, cors, *same-origin
        cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
        credentials: "same-origin", // include, same-origin, *omit
        headers: {
            "Content-Type": "application/json; charset=utf-8",
            // "Content-Type": "application/x-www-form-urlencoded",
        },
        redirect: "follow", // manual, *follow, error
        referrer: "no-referrer", // no-referrer, *client
        body: JSON.stringify(data), // body data type must match "Content-Type" header
    })
    .then(response => response.json()) // parses response to JSON
    .catch(error => console.error(`Fetch Error =\n`, error));
};

const test1 = () => {
  postData(`https://manniru.firebaseio.com/vue/test1/.json`, {answer: 42})
  .then(data => console.log(data)) // JSON from `response.json()` call
  .catch(error => console.error(error));
}

var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Mannir!',
    myJson : null,
  },
  created() {
    // console.log(+new Date())
    fetch('https://manniru.firebaseio.com/forms/-Ky5HYCmhB7XTRYSH2PJ/.json')
    .then(response => { return response.json(); })
    .then(json => {
      //  message = json.name
      console.log(json.name)
    })
  }
})

test1();