📃
Vucript Documentation
  • Vucript
  • Setup
  • Usage
  • Language Reference
    • Reactive Values & Functions
    • Computed
    • Lifecycle Methods
    • Import Components
    • Prop
    • Using Ohter Libraries
Powered by GitBook
On this page

Was this helpful?

  1. Language Reference

Using Ohter Libraries

You can use other libraries when you're writing Vucript.

Let's use HTTP requiest library axios with Vucript.

First, you need to install axios via npm

$ npm install axios

Let's see the example which is using yesno API which returns YES or NO randomly.

import { reactive } from "Vucript";
import axios from "axios";
let yesorno: reactive<string> = 'thinking';
const onMounted = async () => {
    try {
        const response = await axios.get("https://yesno.wtf/api");
        yesorno = response.data["answer"];
    } catch (error) {
        console.error(error);
    }
};

The code above is compiled to

import { defineComponent, ref, onMounted } from "vue";
import axios from "axios";
export default defineComponent({
  setup() {
    const yesorno = ref<string>("thinking");
    onMounted(async () => {
      try {
        const response = await axios.get("https://yesno.wtf/api");
        yesorno.value = response.data["answer"];
      } catch (error) {
        console.error(error);
      }
    });
    return { yesorno };
  },
});

"YES" or "NO" response is stored to valiable yesorno.

PreviousProp

Last updated 4 years ago

Was this helpful?