这次给大家带来的是,在scope怎么使用vue,我们都知道vue slot插槽可以传递任何属性或html元素,但是在调用组件的页面中我们可以使用 template scope="props"来获取插槽上的属性值,获取到的值是一个对象,这篇文章就给大家好好分析一下。
上面已经说了 scope获取到的是一个对象,是什么意思呢?我们先来看一个简单的demo就可以明白了~
<!DOCTYPE html>
<html>
<head>
<title>Vue-scope的理解</title>
<script src="./libs/vue.js"></script>
<link rel="stylesheet" href="./css/index.css" rel="external nofollow" />
<script src="./js/scope.js"></script>
</head>
<body>
<div id="app">
<tb-list :data="data">
<template scope="scope">
<div class="info" :s="JSON.stringify(scope)">
<p>姓名:{{scope.row.name}}</p>
<p>年龄: {{scope.row.age}}</p>
<p>性别: {{scope.row.sex}}</p>
<p>索引:{{scope.$index}}</p>
</div>
</template>
</tb-list>
</div>
<script id="tb-list" type="text/x-template">
<ul>
<li v-for="(item, index) in data">
<slot :row="item" :$index="index"></slot>
</li>
</ul>
</script>
<script type="text/javascript">
new Vue({
el: '#app',
data() {
return {
data: [
{
name: 'kongzhi1',
age: '29',
sex: 'man'
},
{
name: 'kongzhi2',
age: '30',
sex: 'woman'
}
]
}
},
methods: {
}
});
</script>
</body>
</html>js 代码如下:
Vue.component('tb-list', {
template: '#tb-list',
props: {
data: {
type: Array,
required: true
}
},
data() {
return {
}
},
beforeMount() {
},
mounted() {
},
methods: {
}
});从上面返回的scope属性值我们可以看到,scope返回的值是slot标签上返回的所有属性值,并且是一个对象的形式保存起来,该slot有两个属性,一个是row,另一个是$index, 因此返回 {"row": item, "$index": "index索引"}; 其中item就是data里面的一个个对象。
相信看了以上介绍你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
相关阅读:
立即学习“前端免费学习笔记(深入)”;
beta v1.1版本为第一个版本,简单的整合了基础功能,各位站长拿到程序后,不要纠结后台的功能简单,后续将不断更新扩展。在beta v1.1版本使用过程中遇到什么问题,请登录 www.loftto.com 进行反馈! 安装说明######重要提醒:程序不支持二级目录安装,请使用一级目录或二级目录绑定!#第一步,确定你的服务器支持PHP+mysql。#第二步,确定你的服务器开启了gd库。#第三步,
0
以上就是在scope怎么使用vue的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号