繁体   English   中英

如何将数据从 vue 组件传递到 Laravel 中的视图(HTML)

[英]How to pass data from vue component to view(HTML) in laravel

我正在尝试将数据从 vue 组件传递到刀片文件。 我尝试创建道具,但它对我不起作用。 是否有可能将对象传递给道具以获取数据? 我是新来的laravel。 我想将主题、消息、日期、条件和模块名称的数据传递给刀片文件(视图) 我一直在寻找这个,但找不到一个可以说明这一点的答案。

谢谢!

刀片.php

  <div id="app">
       <email-component
          email_edit_route="{{ route('havence.automail.edit',['id'=>$mailTemplates->id]) }}"
       >
       </email-component>

 </div>

Vue.js

<script>
    import Vue from 'vue'
    import axios from 'axios'
    import MarkdownIt from 'markdown-it'
    import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
    var msg_editor;


    const md = new MarkdownIt({
        linkify: true
    })

  export default {
    props: ['email_creation_link', 'email_index_route', 'email_edit_route','conditions','modules'],

    components: {

    },


    data() {
        return {
            template: {
                subject: '',
                message: '' ,
                days: '',
                condition_id: 1,

            },
            options:[
                {
                    display:'Client Name',
                    actual:'Client name'
                }, 
                {
                    display:'Joined Date',
                    actual:'Joined date'
                },
                {
                    display:'Module Name',
                    actual:'Module name'
                },
                {
                    display:'Last Seen',
                    actual:'Last seen'
                },
            ],


              showName: false,


        }
    },


    mounted(){
             var self = this;

            ClassicEditor
            .create(document.querySelector( "#msg"),
                {
                })
            .then(editor => {
                msg_editor = editor;
                editor.model.document.on( 'change:data', () => {
                    self.template.message = msg_editor.getData();
                });
            })

            .catch(error => {
                console.error(error);
            })

        }, 

    methods: {

        //Drag items
        dragstart: function(item, e){
            this.draggingItem = item;
            e.dataTransfer.setData('text/plain', item.actual);
        },
        dragend: function(item,e) {
            e.target.style.opacity = 1;
        },
        dragenter: function(item, e) {
            this.draggingItem = item;
        },
        //content
        replaceVariables(input)
        {
            let updated = input
            return updated
        },
        //hidecontent
        showHide: function(e)
        {
            console.log("Show "+e.target.value+ " fields")
            this.showName = e.target.value !== ''
        },
        fetch()
        {
            //request data
            axios.get(this.email_index_route,this.template)
                .then((res) => {
                    this.template = res.data.template;

                })
        },
        save()
        {
            //save data to db
            axios.post(this.email_index_route, this.templates)
                .then((res) => {
                    alert('Mail sent successfull!')
                })
        },
        addToMail: function(type, text)
        {
            if (type == 'message') {
                this.template.message += text;
                msg_editor.setData(this.template.message);
            }
        },

        //user name replace
        replaceVariables() {
            return this.replaceVariables(this.options || '')
        },
    }
  }
</script>

快速解决。 :为什么不将数据存储在本地存储中并从 laravel Blade 中获取? 下一个解决方案:您可以从 vue 触发全局事件并在 laravelblade 上监听。

为什么不通过ajax post call发送数据并从控制器获取数据? 然后将数据对象传递给刀片模板。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM