Vitepress -- insert my own JS on a particular page #3098
-
Sorry if this is a totally newbie question but I'd like to put a custom API query on a particular markdown page in my Vitepress site.
The script above works by itself but I can't figure out how to insert it into my particular Vitepress markdown file. When I put the code directly in the markdown I get the error: If I remove the I tried searching for how to do this but I don't really even know what to search for. I'm guessing it has to do with extending the Theme? Maybe it's an enhancement? Is there a way I can inject JS on a markdown file and I just missed it in the docs? Any recommendations, and best practice recommendations, are appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You should just install axios: Then write code like this: <script setup>
import axios from "axios";
function callapi() {
axios.post("https://XXXX.ap-southeast-2.amazonaws.com/v1/XXXX")
.then(response => {
console.log(response.data);
}).catch(error => console.error(error));
}
</script>
<button @click="callapi()">Test Button</button> Basically you'll need to write vue code. |
Beta Was this translation helpful? Give feedback.
You should just install axios:
npm add axios
Then write code like this:
Basically you'll need to write vue code.