Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using multiple dynamic slot names (Invalid dynamic argument expression) #9781

Closed
tanasebutcaru opened this issue Mar 27, 2019 · 10 comments · Fixed by #9785
Closed

Error using multiple dynamic slot names (Invalid dynamic argument expression) #9781

tanasebutcaru opened this issue Mar 27, 2019 · 10 comments · Fixed by #9785

Comments

@tanasebutcaru
Copy link

tanasebutcaru commented Mar 27, 2019

Version

2.6.10

Reproduction link

https://github.com/tbutcaru/v-issue-multiple-dynamic-slot-names

Steps to reproduce

  1. Clone this repo: https://github.com/tbutcaru/v-issue-multiple-dynamic-slot-names
  2. Run: npm install
  3. Run: npm run serve

What is expected?

Multiple dynamic slot names should work as expected.

What is actually happening?

The following error is thrown:

Invalid dynamic argument expression: attribute names cannot contain spaces, quotes, <, >, / or =.#[headerslot]>Header slot</template>
    Default slot
    <template #[footerslot]

If one of the dynamic slot names is made static (doesn't matter which), the application is working.

My investigation
  • file: node_modules/vue-template-compiler/build.js
  • line: 2563 (inside attrs.forEach(function (attr) {) added the following warn:
warn$1('--------------->> ' +  attr.name);
Investigation results:
  1. In the working scenario with only one dynamic slot name: the value of that dynamic slot name is #[headerslot]
  2. In the error scenario with two dynamic slot names: the value of the first dynamic slot name is
#[headerslot]>Header slot</template>
    Default slot
    <template #[footerslot]

So, it looks like the compiler doesn't know how to extract just the attribute when there are multiple dynamic slot names.

@posva posva added the bug label Mar 27, 2019
@Justineo
Copy link
Member

Reproduction

@michalzaq12
Copy link

The shorthand is only available when an argument is provided. Try to use:
<template v-slot:[dynamicSlotName]> ... </template>

@tanasebutcaru
Copy link
Author

The shorthand is only available when an argument is provided. Try to use:
<template v-slot:[dynamicSlotName]> ... </template>

I've tried that before creating the issue and the result is the same 😞

@davis90
Copy link

davis90 commented Jan 22, 2020

Hi everyone!

What new about this ? I still have the problem in 2.6.11 reproduce here

@davis90
Copy link

davis90 commented Jan 22, 2020

After many tries, I found a way to make multi dynamic slots work. When i add keys to root element of the dynamics slot templates, it fall in work:

this doesn't work: reproduce here

   <template #[slot1]>
       <p>slot test</p>
   </template>
   <template #[slot2]>
       <p>slot test2</p>
    </template>

// got "Invalid dynamic argument expression: attribute names cannot contain spaces, quotes, <, >, / or ="

this work: reproduce here

   <template #[slot1]>
       <p key="1">slot test</p>
   </template>
   <template #[slot2]>
       <p key="2">slot test2</p>
    </template>

// work fine

Why i need to add keys to make it work? I missed something.

@SreeChandan
Copy link

@davis90 's solution worked for me. I don't get why it works too.

@Moizsohail
Copy link

Why are the errors so misleading in vue. Thanks though your solution worked

posva added a commit that referenced this issue Sep 21, 2020
* fix(#9781): non greedy `dynamicArgAttribute` RegExp 

* test(parser): add test case for multiple dynamic slot names

* test: add test with value

Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
@016
Copy link

016 commented Apr 1, 2021

Hey all, I am using vue 2.6.10, I got same problem, after google something I found this way to fix it.

  <template v-slot:[`content_`+ValueA]="" >
    12345
  </template>
  <template v-slot:[`content_`+ValueB]>
    12345+101
  </template>

the main idea is add '=""' after [], remember only last one can keep without ="", for short just add ="" for all v-slot

good luck for everyone.

btw VUE is good.

a online demo based on @Justineo demo code

@valentinoli
Copy link

Solution proposed by @016 seems to work and is less verbose than adding keys

@FuriosoJack
Copy link

FuriosoJack commented Jan 29, 2022

Hey all, I am using vue 2.6.10, I got same problem, after google something I found this way to fix it.

  <template v-slot:[`content_`+ValueA]="" >
    12345
  </template>
  <template v-slot:[`content_`+ValueB]>
    12345+101
  </template>

the main idea is add '=""' after [], remember only last one can keep without ="", for short just add ="" for all v-slot

good luck for everyone.

btw VUE is good.

a online demo based on @Justineo demo code

Thanks look. I working with bootstrap-vue

<template v-slot:[`cell(`+rango.abreviatura+`)`]="data" v-for="rango in rangos">
            <b-form-radio v-model="data.item.valor" :name="'radio-size-'+data.item.id" size="sm" value="1"></b-form-radio>
        </template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants