title: How do I send values from golang to vue js (server to client)?
body: <p>super newbie developer here. So say I have a variable (key) (i.e. type string) in golang that I want to send client-side (Vue js). I've tried sending it locally but Vue js isn't able to read it. So I'm 100% sure I'm doing it wrong within golang.</p>
  <p>Would I need to POST it to a local server (ex: localhost:3001) and GET it from vue js?
  How should I send this POST request in go? Are there better options?</p>
  <p>Snippet of current vue code :</p>
  <pre><code>&lt;template&gt;
    &lt;div class=&quot;about&quot;&gt;
      &lt;h1&gt;This is an about page&lt;/h1&gt;
      &lt;p&gt;Lorem&lt;/p&gt;
    &lt;/div&gt;
  
        &lt;div v-if=&quot;key !== null&quot;&gt;
      &lt;p&gt;{{key}}&lt;/p&gt;
      &lt;/div&gt;
      &lt;div v-else&gt;
        &lt;p&gt;Waiting for key....&lt;/p&gt;
      &lt;/div&gt;
      
  &lt;/template&gt;
  
  &lt;script&gt;
  export default {
    props: ['id'],
    data() {
      return {
        job: null,
        key: null,
      }
    },
    mounted() {
  
      fetch('http://localhost:3001', {
                      method: 'GET'
                  })
        .then(res =&gt; res.json())
        .then(data =&gt; this.key = data.message)
        .catch(err =&gt; console.log(err.message))
    }
  }
  &lt;/script&gt;
  </code></pre>
  <p>Thank you!</p>
  <p>EDIT: My current golang code</p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;fmt&quot;
      &quot;log&quot;
      &quot;net/http&quot;
  )
  
  type ResponseData struct {
      Message string `json:&quot;message&quot;`
  }
  
  func getData(w http.ResponseWriter, r *http.Request) {
      json.NewEncoder(w).Encode(ResponseData{Message: &quot;Hello, World&quot;})
  }
  
  func main() {
      http.HandleFunc(&quot;/&quot;, getData)
  
      fmt.Println(&quot;Server listening on port 3001&quot;)
      log.Panic(
          http.ListenAndServe(&quot;:3001&quot;, nil),
      )
  }
  </code></pre>
  <p>When I go http://localhost:3001/, I am able to see the message <code>{&quot;message&quot;:&quot;Hello, World&quot;}</code>. However, I am still not receiving anything when I run a GET command on vue. What am I doing wrong in golang? Also, how do I program it so that I can send my own variable to the <code>getData()</code> function and display it on port 3001? Thank you.</p>