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

Empty string is undefined #52

Closed
pixelfriese opened this issue Jan 23, 2017 · 4 comments
Closed

Empty string is undefined #52

pixelfriese opened this issue Jan 23, 2017 · 4 comments

Comments

@pixelfriese
Copy link

pixelfriese commented Jan 23, 2017

Hi,

in my application I set an initial data variable as empty string in my component. My next step is to get the final value from an async call.

Within this time from initialization of the data variable and the overwrite from the ajax call the value is undefined. I have tested it without the ajax call and it is independent of it. If I have defined my variable in the data function of my component as an empty string, it got undefined.

My current dirty solution is to use an string with an empty line in it, because I don´t want an 'undefined' text in my page title.

This very simple example produce an undefined page title:

module.exports = {
    data: function () {
        return {
            title: ''
        }
    }

    metaInfo: function () {
        return {
            title: this.title,
            titleTemplate: '%s | MySite'
        }
    }
}
@pixelfriese pixelfriese changed the title Initial value null or empty string is undefined Empty string is undefined Jan 23, 2017
@jazoom
Copy link
Contributor

jazoom commented Mar 14, 2017

I think this is the same as #32.

@atinux
Copy link
Member

atinux commented Apr 6, 2017

Should be fixed with #81

@atinux atinux closed this as completed Apr 6, 2017
issaTan added a commit to issaTan/vue-meta that referenced this issue Sep 29, 2018
@issaTan
Copy link
Contributor

issaTan commented Sep 29, 2018

@atinux I'm sorry, but it still have this problem.
And I found the reason, here's the code.

   // backup the title chunk in case user wants access to it
    if (info.title) {
      info.titleChunk = info.title;
    }

    // replace title with populated template
    if (info.titleTemplate) {
      info.title = applyTemplate(component)(info.titleTemplate)(info.titleChunk);
    }
    ...
    var applyTemplate = function (component) { return function (template) { return function (chunk) { return typeof template === 'function' ? template.call(component, chunk) : template.replace(/%s/g, chunk); }; }; };

wx20180929-181139

At line 514, info.title === '' is true, so info.titleChunk is undefined, but info.titleTemplate === '%s | MySite' still true, so when template.replace(/%s/g, chunk), it will return undefined | MySite.

And I create a PR, please fixed it or merge the PR, thanks for your work.

@arenddeboer
Copy link

It would be awesome if the supplied PR can be merged, this issue is still present as described by IssaTan.

atinux added a commit that referenced this issue Nov 26, 2018
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

5 participants