Last active
September 21, 2017 23:58
-
-
Save lazyTai/90e8f5f5987fc1354a0a34b8ef7fac08 to your computer and use it in GitHub Desktop.
cssString=>computer==>width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rules: [ | |
{test: /\.css$/, use: ['to-string-loader','css-loader']}, | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cssIntoBody(cssString,{ | |
width:window.innerWidth+"px", | |
height:window.innerHeight+"px", | |
background:'#eee' | |
},"home") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ =require("underscore"); | |
function addcss(css,key){ | |
var areayDom=document.querySelector("style[key='"+key+"']") | |
if(areayDom){/*存在*/ | |
areayDom.textContent=css | |
}else{ | |
var head = document.getElementsByTagName('head')[0]; | |
var s = document.createElement('style'); | |
s.setAttribute('type', 'text/css'); | |
s.setAttribute('key', key); | |
if (s.styleSheet) { // IE | |
s.styleSheet.cssText = css; | |
} else { // the world | |
s.appendChild(document.createTextNode(css)); | |
} | |
head.appendChild(s); | |
} | |
} | |
export default function(cssString,data,key){ | |
_.templateSettings = { | |
interpolate: /\"\{\{(.+?)\}\}\"/g | |
}; | |
var afterCss=_.template(cssString)(data) | |
addcss(afterCss,key) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component.js | |
const cssString = require('./css.css').toString(); | |
var _ =require("underscore"); | |
function addcss(css){ | |
var head = document.getElementsByTagName('head')[0]; | |
var s = document.createElement('style'); | |
s.setAttribute('type', 'text/css'); | |
if (s.styleSheet) { // IE | |
s.styleSheet.cssText = css; | |
} else { // the world | |
s.appendChild(document.createTextNode(css)); | |
} | |
head.appendChild(s); | |
} | |
_.templateSettings = { | |
interpolate: /\"\{\{(.+?)\}\}\"/g | |
}; | |
var afterCss=_.template(cssString)({width:"100px",height:"111px"}) | |
addcss(afterCss) | |
debugger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment