[Vuejs]-How to use script in vue

0👍

Find the problem, if you want to render rich text, especially rich text with a srcipt tag, the tag needs to be escaped.
But,Although v-html can render tags, but can’t execute the contents of the script, if I want to know how to execute the contents of the script, I have a way.

0👍

Use axios…

axios.get function uses a Promise.
When the API returns data successfully, the code within the then block is executed.

   mounted() {
      axios.get(url).then(response => {
        this.results = response.data
      })
   }

Here is the link
Using Axios to Consume APIs
from official site.

0👍

Make sure to include your js code inside scripts tags, like below;

<script> include </script>

That should fix your problem.

0👍

you should put all your JS in the script tag. The basic structure of a Vue app is like this.

<template>
   //Your html here
</template>
<script>
  export default {
     data(){
        return {
           content : ""
         }
      },
     mounted(){
         axios.get(url).then(response => {
           this.content = response.data     //depends on the structure of response
         }).then(error => {
           console.log(error);
          });
        }
      }
<script>

Hope this helps 🙂

Leave a comment