[Vuejs]-Django rest framework websockets auto update

0👍

You just need to update data after patch method

export default {
  name: "HelloWorld",
  setup() {
    const state = reactive({
      numbers: [],
      inputValue: 1,
      pk: 1,
    });
    const updateData = () => {
      return axios
        .get("http://127.0.0.1:8000/api/numbers-list/")
        .then((res) => (state.numbers = res.data));
    }
    function changeNumber() {
      const data = {
        number: state.inputValue,
      };
      console.log(data);
      axios
        .patch(`http://127.0.0.1:8000/api/number-update/${state.pk}/`, data)
        .then(updateData);
    }
    onMounted(updateData);
    return {
      changeNumber,
      state,
    };
  },
};

Leave a comment