[Vuejs]-Vue 3: Can not access Object key of Object by props (in brackets)

0👍

When using a string it works in the below snippet. Are you sure the JSON.parse(JSON.stringify(props.formMethod)) is returning "makeUserSignInForm" as a string?

const directur = {
    makeUserSignInForm: 'Hello',
};

// const accessor = JSON.parse(JSON.stringify(props.formMethod));
const accessor = "makeUserSignInForm";

console.log(directur); // logs the object.
console.log(accessor); // makeUserSignInForm

console.log(directur.makeUserSignInForm); // Hello

console.log(directur['makeUserSignInForm']); // Hello

console.log(directur[accessor]); // Hello

Leave a comment