简体   繁体   English

Vue.js中JSON对象的值

[英]Values from JSON object in Vue.js

I'm using Auth0 , Vue.js , Vuetify , and Stripe . 我正在使用Auth0Vue.jsVuetifyStripe

Relevant code: 相关代码:

JSON Object (I've blanked out unrelated values) JSON对象(我删除了不相关的值)

{ "sub": "", "given_name": "", "family_name": "", "nickname": "", "name": "", "picture": "", "gender": "", "locale": "", "updated_at": "", "https://example.com/stripe_customer_id": "cus_id" }

HTML: HTML:

<v-chip disabled>{{ getProfile.https://example.com/stripe_customer_id }}</v-chip>
<v-chip disabled>{{ getProfile.nickname }}</v-chip>
<v-chip disabled>{{ getProfile.gender }}</v-chip>
<v-chip disabled>{{ getProfile.locale }}</v-chip>
<v-chip disabled>{{ getProfile.updated_at }}</v-chip>

As you'd expect, the first line doesn't work due to the HTML link format (specifically, the forward slashes). 如您所料,由于HTML链接格式(特别是正斜杠),第一行不起作用。 Is there a way to extract the value of that field? 有没有办法提取该字段的值?

Unfortunately, the key must be in namespace format due to Auth0 rules (tokens retrieved from Auth0 will omit any added fields that aren't formatted that way. I'm using an Auth0 rule to create the Stripe customer post-registration (if that's at all relevant). 不幸的是,由于Auth0规则,密钥必须采用命名空间格式(从Auth0检索的令牌将忽略未格式化的所有添加字段。我正在使用Auth0规则来创建Stripe客户后注册(如果位于所有相关)。

I've tried a few things and all of them result in a raw expression error. 我尝试了几件事,所有这些都会导致raw expression错误。 Not sure what to try next. 不知道下一步该怎么做。

So, is there any way to easily extract that value? 那么,有什么方法可以轻松地提取该值? Thanks in advance! 提前致谢!

Use 采用

getProfile['https://example.com/stripe_customer_id']

To access the keys having dots or / . 访问带有点或/的键。 Any js object's property can be access with object.['key'] 任何js对象的属性都可以通过object.['key']

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

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