【问题标题】:Send variable javascript to controller laravel to update vueJS将变量 javascript 发送到控制器 laravel 以更新 vueJS
【发布时间】:2020-10-21 14:03:31
【问题描述】:

我正在将数据从我的模态发送到一个控制器以更新数据,但我不知道如何声明我的变量以及我必须如何发送此变量...

我的实际代码是:

vuejs

<script>

export default {

    data() {
        return {
            datosUsuario: [],
            isOpen: false,
            selectedItem: {},
            nombreUsuario: nombreUsuario,
        };

    },
    created: function () {
        this.cargar();
    },
    methods: {
        cargar: function () {
            let url = "/getDatosPersonales";
            axios
                .get(url)
                .then((response) => {
                    this.datosUsuario = response.data;
                })
                .catch((error) => console.error(error));
        },
        actualizar: function(){
            let nombreUsuario = document.getElementById('nombre');
            let url = "/actualizarDatos";
            axios
                .post(url)
                .then((response) => {
                    console.log(response);
                    console.log(nombreUsuario);
                })
                .catch((error) => console.error(error))
        },
        setSelectedItem(item) {
            this.selectedItem = item;
        }
    },
};

当我点击我的按钮时,这会调用一个函数“actualizar”

<input type="submit" class="btn btn-primary" value="Guardar" @click="actualizar">

我正在检查如果我点击按钮转到我的控制器并没问题,但现在我需要在更新请求中传递数据,我不知道。

非常感谢您的帮助

【问题讨论】:

    标签: javascript php laravel vue.js


    【解决方案1】:

    我得到解决我的问题,这很容易。分享我的解决方案

    actualizar: function(){
                let url = "/actualizarDatos";
                axios
                    .post(url, {
                        idUsuario: this.datosUsuario.id,
                        nombreUsuario: this.datosUsuario.nombre,
                        email: this.datosUsuario.email,
                        direccion: this.datosUsuario.direccion,
                    })
                    .then((response) => {
                        console.log(response);
                        
                    })
                    .catch((error) => console.error(error))
            },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-04
      • 2021-04-20
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多