2.5.17
https://codesandbox.io/s/m674vkw2j
Use the optional chaining operator in a template:
{{ user?.id }}
Output the users id in the template or blank for undefined
Optional chaining works just fine in the script section of a SFC Vue component but does not work in the template section.
For reference, this is in an Nuxt.js 2.0 project stock settings with the babel optional chaining plugin
Version is actually 15.4.2 with Vue 2.5.17
Babel is actually not used for in-template strings: See https://github.com/vuejs/vue/issues/6307
Not sure if anything changed regarding this 馃
The template section does not go through the same Babel configuration of your script section. I don't think there's an easy way to do this in the 2.x compiler setup, but we should consider configurable post-processing of render functions in the 3.0 compiler.
@yyx990803 Did you do it? :D
Most helpful comment
The template section does not go through the same Babel configuration of your script section. I don't think there's an easy way to do this in the 2.x compiler setup, but we should consider configurable post-processing of render functions in the 3.0 compiler.