[Vuejs]-Vuejs sending a GET request with a method

1👍

Simply add an onclick listener and bind it with a method:

<input id="sendButton" type="submit" value="search" @click="sendRequest()> 
methods: {
    sendRequest() {
        if (this.$refs.input.value) {
            axios.get("http://localhost:8080/Books/getByParam/{param}", {
                params: {
                    param: this.$refs.input.value
                }   
            })
            .then(response => (this.bookResponse = response.data))
        }
    }
}

As for the param, you can simply keep track of the value using $ref. Although there are many alternatives.

<input ref="input" type="text" placeholder="Search" />

The form is only submitted if the input has a value.

Leave a comment