HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="app">
<div>
<ele-import
:fields="fields"
:filepath="filepath"
:append="append"
:formatter="formatter"
:request-fn="requestFn"
:rules="rules"
:tips="tips"
:title="title"
:visible.sync="visible"
@close="handleCloseImport"
@finish="handleFinishImport"
></ele-import>
<el-button @click="handleOpen" type="primary">点我打开</el-button>
<div>
{{tableData}}
</div>
</div>
</div>
const Main = {
data() {
return {
// 弹窗的标题
title: '导入人员',
// 提示信息
tips: ['名字必填', '年龄必填', '年龄请填写数字'],
// 假如数据库中是`name`字段, 而Excel模板列是`名字`, 就需要写成 name: '名字'
// ele-import 内部会抛弃非定义在fields里的列
fields: {
name: '名字',
age: '年龄',
city: '所在城市'
},
// 附加数据,每条记录都会加上这两个字段和值
append: {
company: '腾讯',
leader: '小马哥'
},
// formatter起到替换数据的作用
formatter: {
// 可以是对象, 在发送请求时, '深圳' 将被替换成 1, '广州' 被替换成 2
city: {
1: '深圳',
2: '广州'
},
// 可以是函数, 在发送请求时, `age` 将加1, 例如 原数据是 19 -> 20
age: function(value, row) {
return value + 1
}
},
// 参数校检, 和 element-ui 中 form表单中传递的rules一样, 都是使用的 async-validator 库
// https://element.eleme.cn/#/zh-CN/component/form#biao-dan-yan-zheng
rules: {
name: { type: 'string', required: true, message: '名字必填' },
age: [
{ type: 'number', message: '年龄必须为数字' },
{ required: true, message: '年龄必须填写' }
]
},
// Excel模板下载地址
// 注意, 只能是.xlsx的文件, .xls或者.cvs都会报错
filepath: 'https://raw.githubusercontent.com/dream2023/vue-ele-import/master/public/user.xlsx',
// 控制弹窗, 和dialog的visible一样
// https://element.eleme.cn/#/zh-CN/component/dialog
visible: false,
tableData: ""
}
},
methods: {
// requestFn函数会被注入请求的数据
// 需要返回一个Promise对象
async requestFn(data) {
this.tableData = JSON.stringify(data)
console.log(data)
// 演示代码
// 1、如果没有针对ele-import做过接口约定, 可以采用如下形式:
// try {
// const res = await axios.post('/user', data)
// return Promise.resolve()
// } catch (error) {
// // error经过一系列转化, 转为
// const errorData = this.getErrorMessage(error)
// {0:{ age: '年龄为数字', city: '城市必填'}, 2:{ age: '年龄为数字'} } // 0 和 2 分别是行号
// return Promise.reject(errorData)
// }
// 2、如果针对ele-import做过接口约定, 当校检错误时, 后端返回的 error 就是上述错误形式, 则可直接
// return axios.post('/user', data)
// 总结: 无论如何总要返回一个Promise对象
return Promise.resolve()
},
handleCloseImport() {
console.log('弹窗关闭了~')
},
handleFinishImport() {
console.log('导入完毕了~')
},
handleOpen() {
this.visible = true
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
Also see: Tab Triggers