【问题标题】:Vuejs 2 Sending props to xxx.vue fileVuejs 2 将道具发送到 xxx.vue 文件
【发布时间】:2017-04-04 04:25:12
【问题描述】:

通常你会这样发送道具

Vue.component('child', {
  // camelCase in JavaScript
  props: ['myMessage'],
  template: '<span>{{ myMessage }}</span>'
})

我如何通过 require 来实现:

Vue.component('lw-login', require('./components/login.vue'));

Laravel 刀片模板:

<lw-login
        heading="Login"
        action="{{ route('login') }}"
        email="E-mailadres"
        passwordrequest="{{ route('password.request') }}"
></lw-login>

login.vue: 见{{标题}} 我收到此错误:

[Vue warn]: Property or method "heading" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. 

(位于 C:\Code\cms\resources\assets\js\components\login.vue)

<template>
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">{{ heading }}</div>
                    <div class="panel-body">
                        <form class="form-horizontal" role="form" method="POST" :action="action">


                            etc .....

<script>
    export default {
        mounted() {
            props: ['heading','action','passwordrequest']
        }
    }
</script>

【问题讨论】:

  • ./components/login.vue 不包含一个可以有 props 的 vue 组件吗?
  • 我通过模板发送它们,添加到我的问题中。
  • 您的模板已经包含lw-login?不应该是其他标签吗?
  • 我添加了更多代码。希望你能帮助我:))
  • 您的代码中存在语法错误,我不确定您为什么没有收到此错误,但您在里面安装了props: ['heading','action','passwordrequest']

标签: vue.js vuejs2 vue-component


【解决方案1】:

改变了这个:

<script>
    export default {
        mounted() {
            props: ['heading','action','passwordrequest'],
        }
    }
</script>

到这个:)) :

<script>
    export default {
        props: ['heading','action','passwordrequest'],
        mounted() {

        }
    }
</script>

【讨论】:

    猜你喜欢
    • 2017-09-14
    • 2021-08-26
    • 2017-10-11
    • 2018-11-24
    • 2020-12-25
    • 2017-12-23
    • 2021-10-27
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多