【问题标题】:How to solve "interpolation inside attributes has been removed". Vue and Laravel 5.8如何解决“属性内的插值已被删除”。 Vue 和 Laravel 5.8
【发布时间】:2020-06-18 03:43:33
【问题描述】:

我正在尝试使用 Vue 和 Laravel 将用户身份验证 ID 传递给隐藏,但是当我提交表单时,我收到此错误:

value="{{ Auth::user()->id }}":属性内的插值已被删除。请改用 v-bind 或冒号简写。例如,不要使用<div id="{{ val }}">,而是使用<div :id="val">

请帮助我克服这个错误。

我的组件代码是

<template>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Example Component</div>
                <button class="btn btn-success" @click="updateLocation">Update Position</button>
                <div class="card-body">

                    <div id="realtimemap" style="height: 412px; width: 100%;"></div>
                    <input type="hidden" class="form-control" name="user_id" id="user_id" value="{{ Auth::user()->id }}">
                </div>
            </div>
        </div>
    </div>
</div>

<script>

export default{

    data(){

        return{
            map:null,
            marker:null,
            center:{lat: 10, lng: 10},
            data:null,
            lineCoordinates:[]
        }
    },

    methods:{

        mapInit(){


            this.map = new google.maps.Map(document.getElementById('realtimemap'),{
                center: this.center,
                zoom: 8
            });

            this.marker = new google.maps.Marker({
                map: this.map,
                position: this.center,
                animation:"bounce",
            });
        },

        updateMap(){
            let newPosition = {lat:this.data.lat,lng:this.data.long};
            this.map.setCenter(newPosition);
            this.marker.setPosition(newPosition);

            this.lineCoordinates.push(new google.maps.LatLng(newPosition.lat,newPosition.lng));

            var lineCoordinatesPath = new google.maps.Polyline({
                path: this.lineCoordinates,
                geodesic: true,
                map: this.map,
                strokeColor: '#FF000',
                strokeOpacity: 1.0,
                strokeWeight: 2
            });
        },

        updateLocation(){

            let randomNumber=Math.random();

            let position={
                lat:10+randomNumber,
                long:10+randomNumber
            };

            axios.post('/api/map',position).then(response=>{
                console.log(response);
            })
        }

    },

    mounted() {
        console.log('Component mounted.');
        this.mapInit();
    },
    created(){
        Echo.channel('location')
            .listen('SendLocation', (e) => {
                this.data=e.location;

                this.updateMap();
                console.log(e);
        });
    }
}

控制器代码是

public function store(Request $request)
{


   $input = $request->all(); 

   $realtimelocations = Realtimelocations::create($input);
   event(new SendLocation($realtimelocations));
   return response()->json(['status'=>'success', 'data'=>$realtimelocations]);

}

请告诉我解决方案。 提前致谢。

【问题讨论】:

标签: laravel vue.js


【解决方案1】:

你不能在 vue 组件文件中使用 laravel 刀片插值。 你必须换个方式思考。 例如,您可以将 user 声明为全局 javascript 变量,并在 vue.js 组件中使用它。

【讨论】:

    猜你喜欢
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2017-07-22
    • 2020-03-08
    • 2013-12-14
    相关资源
    最近更新 更多