1

This configuration is extremely unstable. In different browsers, it may work once, or not display data at all.

axiosDate.php

<?php
     $today = date("d.m.Y, H:i");
     echo $today;
?>

component.vue

<template>
<div class="info" id="date">date</div>
</template>
<script>
import axios from 'axios'

mounted() {
axios.get('/axiosDate.php')
    .then(respond => {
 document.getElementById('date').innerHTML = respond.data; 
  }),
}
</script>

tell me how to put the data in the div "date"?

1
  • you should probably read the official vue documentation first. it does not take too long and it is really well written. accessing the DOM directly is something you want to avoid in most modern frontend frameworks. Commented Feb 3, 2020 at 10:57

1 Answer 1

1

try something like this, declare a v-model date, and change the value of the model

<template>
    <div>{{date}}</div>
</template>

<script>
import axios from 'axios'

export default {
  mounted() {
    axios.get('/axiosDate.php')
      .then(respond => {
        this.date = respond.data
    }),
  },
  data(){
    return {
        date:''
    }
  }
}
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

you should update your awnser to have a default export I think. this is no valid js.