Vue.js 组件(component)demo小案例
2023-09-14 09:04:07 时间
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
li {
color: deeppink;
float: left;
width: 20%;
text-align: center;
}
</style>
</head>
<body>
<!--vue组件-->
<div id="app">
<ul>
<game-item v-for="item in games" v-bind:game="item"></game-item>
</ul>
<ul>
<pen-item v-for="item in pens" v-bind:pen="item"></pen-item>
</ul>
</div>
<script>
Vue.component(
'game-item', {
props: ['game'],
template: '<li><h3>{{game.title}}</h3></li>'
});
Vue.component(
'pen-item', {
props: ['pen'],
template: '<li><h3>{{pen.title}}</h3></li>'
});
var app = new Vue({
el: '#app',
data: {
games: [
{title: '五子棋'},
{title: '荒野行动'},
{title: '战争机器人'},
{title: '绝地求生'},
{title: '英雄联盟'}
],
pens: [
{title: '圆珠笔'},
{title: '签字笔'},
{title: '水彩笔'},
{title: '蜡笔'},
{title: '毛笔'}
]
}
});
</script>
</body>
</html>
效果:
相关文章
- vue - 动态绑定 class
- axios和vue-axios的关系
- vue typescript .eslintrc.js
- vue 本地开发时使用localhost与ip访问
- vue的一些小坑
- vue全局组件和局部组件
- CentOS安装nginx,部署vue项目
- vue.js 3.2.22:多选上传图片带缩略图可删除
- vue.js $refs和$emit 父子组件交互
- 打造 Vue.js 可复用组件
- Vue.js
- [Vue-rx] Cache Remote Data Requests with RxJS and Vue.js
- [Vue-rx] Disable Buttons While Data is Loading with RxJS and Vue.js
- vue.js 3.0.5:用vue-i18n开发i18n国际化功能(vue-i18n@9.2.0)
- [Vue] SSR 环境 Storage 与 Vuex 的关系
- Atitit vue.js 把ajax数据 绑定到form表单
- vue+echarts实现动态绘制图表及异步加载数据的方法
- js jquery vue 网络请求封装 服务器 后台
- vue读书笔记
- Vue深度作用选择器
- vue.config.js添加路径别名
- Vue八股笔记自用2
- 解析Vue项目每一个文件夹及文件的作用
- 前端必备技能知识:JS导出Blob流文件为Excel表格、Vue.js使用Blob的方式实现excel表格的下载(流文件下载)
- vue+element ui+腾讯云开发打造会员管理系统之实战教程(六)类别管理