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 in render: "ReferenceError: "sp" undefined" #8228

Closed
windyflying opened this issue May 22, 2018 · 6 comments
Closed

Error in render: "ReferenceError: "sp" undefined" #8228

windyflying opened this issue May 22, 2018 · 6 comments

Comments

@windyflying
Copy link

Version

2.5.16

Reproduction link

https://codepen.io/windyflying/pen/JvzvRb

Steps to reproduce

1.用Chrome或Firefox或Edge打开重现链接,查看结果,代码按预期工作。
2.用IE11打开重现链接,代码不能按预期运行。检查浏览器控制台,有运行时错误,如标题。

What is expected?

没有运行时错误

What is actually happening?

出现运行时错误


编译后的模板函数在IE11、 IE10和工作正常的浏览器的不一致。

@Justineo
Copy link
Member

Seems to be a duplicate of #7946. There is already a PR for this: #8048. It should work correctly if you revert to [email protected] according to the discussions in #7946.

@windyflying
Copy link
Author

windyflying commented May 22, 2018

再次谢谢你。这个PR我昨天看过了,也试过了,还是不行。我用2.5.15的试了,不行。我遇到这个问题看起来和那个问题差不多,但确实不一样。因为我这里的v-for是在template上,并且里面又v-if和v-else。如果换种方式:
<option v-for="sp of product.specs" :selected="sp.id == product.specId ? 'selected' : ''">{{sp.name}}</option>
这样就没问题。

@windyflying
Copy link
Author

error1
vesion

@posva
Copy link
Member

posva commented May 22, 2018

The repro doesn't even run on IE. After fixing the problems there don't seem to be any issue:

const vm = new Vue({
  el: '#app',
  template: '<div id="app"><select style="width:200px"><template v-for="sp in product.specs"><option v-if="sp.id == product.specId" :value="sp.id" selected>{{sp.name}}</option><option v-else :value="sp.id">{{sp.name}}</option></template></select></div>',
  data: {
    product: {
      specId: 2,
      specs: []
    }
  },
  created: function () {
    var self = this 
    setTimeout(function () {
      self.product.specs = [
        {id: 1, name: 'hello'},
        {id: 2, name: 'world'}
      ];
    }, 1e3);
  }
});

BTW it looks like you're trying to mimc v-model

@posva posva closed this as completed May 22, 2018
@posva
Copy link
Member

posva commented May 22, 2018

Oh, yeah, forgot to say, you cannot use template inside select in in-browser templates because some browsers strips them off

@windyflying
Copy link
Author

Thank you very much

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

No branches or pull requests

3 participants