将全局var传递给vue组件属性 [英] Passing a global var to a vue component attribute

查看:92
本文介绍了将全局var传递给vue组件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将php / laravel数据从自定义全局变量传递给我的组件。我已经看到这样的例子直接进入新的Vue({})区域,但是我没有看到任何方法通过直接进入组件来传递它/ p>

I'm trying to pass php/laravel data to my component from a custom global variable. I've seen examples of this going into the new Vue({}) area directly but I haven't seen any way to pass this by going into right into the component

<script>
var itemData = //json object
</script>

<custom-component item-data="ITEMDATAVAR"></custom-component>

我应该指定我有 item-data 在我的组件道具中。问题是我不知道如何告诉我的组件的html我传递变量 itemData 的值而不是字符串 itemData

I should specify that I do have item-data in my component props. The issue is that I'm not sure how to tell my component's html that I'm passing the value of the variable itemData and not the string "itemData"

推荐答案

我认为你指的是动态道具

I think you are referring to dynamic props

<custom-component v-bind:item-data="ITEMDATAVAR"></custom-component>

或使用简写语法

<custom-component :item-data="ITEMDATAVAR"></custom-component>

这篇关于将全局var传递给vue组件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆