[Vuejs]-Get param on another page and edit : Vue, Axios, Django, Python

0👍

Add a detail view in your API

def companyApi(request, id=0):
  if id == 0 and request.method == "GET":
    # return list view
  if id > 0 and request.method == "GET"
    # return detail view

Now in you frontend EditPage:

<script setup>
const route = useRoute()
const companyData = ref({})
watch(() => route.params.id, (v) => {
  fetchCompanyDetail()
})

const fetchCompanyDetail() {
  axios.get(`company/${Route.params.id}`)
    .then(res => {companyData.value = res.data})
}
</script>

Here I’ve used id as a param for your router (not company name) because the fetch API takes ID. You can configure the API to take in company_name and do the same for the vue router param.

Leave a comment