vuejs/docs

SSR guide: add directive transforms

Offen

#1.261 geöffnet am 28.09.2021

 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Vue (5.039 Forks)user submission
enhancementhelp wanted

Repository-Metriken

Stars
 (3.233 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 19T 15h) (3 gemergte PRs in 30 T)

Beschreibung

The Documentation for writing SSR Transforms for directives, beside a very basic noop example, is nonexistent. I've written an Image Lazy Loading Directive and want to provide an SSR Transform. adding simple properties like src or poster are working flawless. When it comes to adding a style attribute the lack of documentation makes it very hard find a solution. The transform isn't very complex, but i'm struggling to add style='background-image:url()". See the Transform code below

export const vueLazyLoaderSSRTransform = (dir, node, context) => {
    if (node.tag === 'img') {
        return {
            props: [createObjectProperty('src', dir.exp)]
        }
    }

    if (node.tag === 'video') {
        return {
            props: [createObjectProperty('poster', dir.exp)]
        }
    }

    return {
        props: [
            createObjectProperty('style',
                createObjectExpression([
                    createObjectProperty(
                        'background-image',
                        createSimpleExpression('url()', true)
                    )
                ])
            )
        ]
    }
}

It would be great to have a more in depth documentation on SSR Transforms

Contributor Guide