Browse Source

ssr directives

dev
Evan You 9 years ago
parent
commit
9f5b292e30
  1. 2
      src/compiler/codegen.js
  2. 8
      src/platforms/web/server/create-renderer.js
  3. 5
      src/platforms/web/server/directives/show.js
  4. 3
      src/platforms/web/server/modules/attrs.js
  5. 3
      src/platforms/web/server/modules/class.js
  6. 9
      src/platforms/web/server/modules/style.js

2
src/compiler/codegen.js

@ -163,7 +163,7 @@ function genDirectives (el) {
}
if (needRuntime) {
hasRuntime = true
res += `{def:__resolveDirective__("${dir.name}")${
res += `{name:"${dir.name}",def:__resolveDirective__("${dir.name}")${
dir.value ? `,value:(${dir.value})` : ''
}${
dir.arg ? `,arg:"${dir.arg}"` : ''

8
src/platforms/web/server/create-renderer.js

@ -44,12 +44,12 @@ export function createComponentRenderer (options = {}) {
// check directives
const dirs = node.data.directives
if (dirs) {
for (let key in dirs) {
let dir = directives[key]
if (dir) {
for (let i = 0; i < dirs.length; i++) {
let dirRenderer = directives[dirs[i].name]
if (dirRenderer) {
// directives mutate the node's data
// which then gets rendered by modules
dir(node)
dirRenderer(node, dirs[i])
}
}
}

5
src/platforms/web/server/directives/show.js

@ -0,0 +1,5 @@
export default function show (node, dir) {
if (!dir.value) {
(node.data.style || (node.data.style = {})).display = 'none'
}
}

3
src/platforms/web/server/modules/attrs.js

@ -0,0 +1,3 @@
export default function renderAttrs () {
}

3
src/platforms/web/server/modules/class.js

@ -0,0 +1,3 @@
export default function renderClass () {
}

9
src/platforms/web/server/modules/style.js

@ -0,0 +1,9 @@
import { hyphenate } from 'shared/util'
export default function renderStyle (styles) {
let res = 'style="'
for (let key in styles) {
res += `${hyphenate(key)}:${styles[key]};`
}
return res + '"'
}
Loading…
Cancel
Save