4.vue.js实例:列表输出

本文介绍如何使用Vue.js中的v-for指令实现动态列表输出。通过一个具体示例展示了如何定义数据结构并将其绑定到HTML元素上,使得列表项能够根据数据的变化而自动更新。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>列表输出</title>
    <link href="css/special.css" rel="stylesheet" />
    <script src="js/vue.min.js"></script>
    <style>
        #app ul li{float:left;width:100%;height:33px;}
    </style>
</head>
<body>
    <div class="pc-content span6">
        <h3>列表输出</h3>
        <div id="app">
            <ul>
                <li v-for="value in todos">
                    {{ value.text }}
                </li>
            </ul>
        </div>
        <p>列表输出使用 v-for(v-for取代了1.0以前版本中的v-repeat) 这个指令就能完成</p>
    </div>
    <script>
        new Vue({
            el: '#app',
            data: {
                todos: [
                  { 'text': '1. Learn JavaScript' },
                  { 'text': '2. Learn Vue.js' },
                  { 'text': '3. Build Something Awesome' }
                ]
            }
        })
    </script>
</body>
</html>
mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 invoker @ vue.runtime.esm.js:5589 mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 invoker @ vue.runtime.esm.js:5589 mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 invoker @ vue.runtime.esm.js:5589 mp.esm.js:481 切换状态: true mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 set @ vue.runtime.esm.js:2642 togglePassword @ login.vue:55 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 setTimeout (async) invoker @ vue.runtime.esm.js:5586 mp.esm.js:481 切换状态: false mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 set @ vue.runtime.esm.js:2642 togglePassword @ login.vue:55 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 setTimeout (async) invoker @ vue.runtime.esm.js:5586 mp.esm.js:481 切换状态: true mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 set @ vue.runtime.esm.js:2642 togglePassword @ login.vue:55 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 setTimeout (async) invoker @ vue.runtime.esm.js:5586 mp.esm.js:481 切换状态: false mp.esm.js:481 [Vue warn]: Property "loginBtnColor" was accessed during render but is not defined on instance. at <App > (anonymous) @ mp.esm.js:481 warn$1 @ vue.runtime.esm.js:1251 get @ vue.runtime.esm.js:2627 _sfc_render @ login.vue:71 renderComponentRoot @ vue.runtime.esm.js:4973 componentUpdateFn @ vue.runtime.esm.js:5100 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5124 callWithErrorHandling @ vue.runtime.esm.js:1356 flushJobs @ vue.runtime.esm.js:1563 Promise.then (async) queueFlush @ vue.runtime.esm.js:1472 queueJob @ vue.runtime.esm.js:1466 (anonymous) @ vue.runtime.esm.js:5118 resetScheduling @ vue.runtime.esm.js:263 trigger @ vue.runtime.esm.js:403 set @ vue.runtime.esm.js:524 set @ vue.runtime.esm.js:2642 togglePassword @ login.vue:55 (anonymous) @ login.vue:71 callWithErrorHandling @ vue.runtime.esm.js:1356 callWithAsyncErrorHandling @ vue.runtime.esm.js:1363 invoke @ vue.runtime.esm.js:5577 setTimeout (async) invoker @ vue.runtime.esm.js:5586 [worker] reportRealtimeAction:fail not support
08-09
list.vue:590 Uncaught (in promise) undefined getFilePageFn @ list.vue:590 await in getFilePageFn (匿名) @ list.vue:162 callWithErrorHandling @ vue.runtime.esm.js:1375 callWithAsyncErrorHandling @ vue.runtime.esm.js:1384 hook.__weh.hook.__weh @ vue.runtime.esm.js:4083 invokeArrayFns @ uni-shared.es.js:361 invokeHook @ uni-h5.es.js:1178 initHooks @ uni-h5.es.js:14923 applyOptions @ uni-h5.es.js:14931 applyOptions @ vue.runtime.esm.js:4915 finishComponentSetup @ vue.runtime.esm.js:8761 handleSetupResult @ vue.runtime.esm.js:8705 setupStatefulComponent @ vue.runtime.esm.js:8668 setupComponent @ vue.runtime.esm.js:8594 mountComponent @ vue.runtime.esm.js:6908 processComponent @ vue.runtime.esm.js:6883 patch @ vue.runtime.esm.js:6479 componentUpdateFn @ vue.runtime.esm.js:7100 run @ vue.runtime.esm.js:192 instance.update @ vue.runtime.esm.js:7134 callWithErrorHandling @ vue.runtime.esm.js:1375 flushJobs @ vue.runtime.esm.js:1609 Promise.then queueFlush @ vue.runtime.esm.js:1501 queueJob @ vue.runtime.esm.js:1495 (匿名) @ vue.runtime.esm.js:7132 triggerEffect @ vue.runtime.esm.js:398 triggerEffects @ vue.runtime.esm.js:388 triggerRefValue @ vue.runtime.esm.js:1019 set value @ vue.runtime.esm.js:1064 (匿名) @ vue.runtime.esm.js:3655 Promise.then setup @ vue.runtime.esm.js:3654 callWithErrorHandling @ vue.runtime.esm.js:1375 setupStatefulComponent @ vue.runtime.esm.js:8639 setupComponent @ vue.runtime.esm.js:8594 mountComponent @ vue.runtime.esm.js:6908 processComponent @ vue.runtime.esm.js:6883 patch @ vue.runtime.esm.js:6479 mountChildren @ vue.runtime.esm.js:6664 processFragment @ vue.runtime.esm.js:6842 patch @ vue.runtime.esm.js:6472 mountChildren @ vue.runtime.esm.js:6664 processFragment @ vue.runtime.esm.js:6842 patch @ vue.runtime.esm.js:6472 mountChildren @ vue.runtime.esm.js:6664 mountElement @ vue.runtime.esm.js:6573 processElement @ vue.runtime.esm.js:6556 patch @ vue.runtime.esm.js:6476 mountChildren @ vue.runtime.esm.js:6664 mountElement @ vue.runtime.esm.js:6573 processElement @ vue.runtime.esm.js:6556 patch @ vue.runtime.esm.js:6476 mountChildren @ vue.runtime.esm.js:6664 processFragment @ vue.runtime.esm.js:6842 patch @ vue.runtime.esm.js:6472 componentUpdateFn @ vue.runtime.esm.js:7022 run @ vue.runtime.esm.js:192 instance.update @ vue.runtime.esm.js:7134 setupRenderEffect @ vue.runtime.esm.js:7148 mountComponent @ vue.runtime.esm.js:6925 processComponent @ vue.runtime.esm.js:6883 patch @ vue.runtime.esm.js:6479 mountChildren @ vue.runtime.esm.js:6664 mountElement @ vue.runtime.esm.js:6573 processElement @ vue.runtime.esm.js:6556 patch @ vue.runtime.esm.js:6476 componentUpdateFn @ vue.runtime.esm.js:7022 run @ vue.runtime.esm.js:192 instance.update @ vue.runtime.esm.js:7134 setupRenderEffect @ vue.runtime.esm.js:7148 mountComponent @ vue.runtime.esm.js:6925 processComponent @ vue.runtime.esm.js:6883 patch @ vue.runtime.esm.js:6479 componentUpdateFn @ vue.runtime.esm.js:7022 run @ vue.runtime.esm.js:192 instance.update @ vue.runtime.esm.js:7134 setupRenderEffect @ vue.runtime.esm.js:7148 mountComponent @ vue.runtime.esm.js:6925 processComponent @ vue.runtime.esm.js:6883 patch @ vue.runtime.esm.js:6479 componentUpdateFn @ vue.runtime.esm.js:7100 run @ vue.runtime.esm.js:192 instance.update @ vue.runtime.esm.js:7134 updateComponent @ vue.runtime.esm.js:6954 processComponent @ vue.runtime.esm.js:6887 patch @ vue.runtime.esm.js:6479 componentUpdateFn @ vue.runtime.esm.js:7100 run @ vue.runtime.esm.js:192 instance.update @ vue.runtime.esm.js:7134 callWithErrorHandling @ vue.runtime.esm.js:1375 flushJobs @ vue.runtime.esm.js:1609 Promise.then queueFlush @ vue.runtime.esm.js:1501 queuePostFlushCb @ vue.runtime.esm.js:1523 queueEffectWithSuspense @ vue.runtime.esm.js:2860 scheduler @ vue.runtime.esm.js:3098 triggerEffect @ vue.runtime.esm.js:398 triggerEffects @ vue.runtime.esm.js:388 triggerRefValue @ vue.runtime.esm.js:1019 (匿名) @ vue.runtime.esm.js:1156 triggerEffect @ vue.runtime.esm.js:398 triggerEffects @ vue.runtime.esm.js:383 triggerRefValue @ vue.runtime.esm.js:1019 (匿名) @ vue.runtime.esm.js:1156 triggerEffect @ vue.runtime.esm.js:398 triggerEffects @ vue.runtime.esm.js:383 triggerRefValue @ vue.runtime.esm.js:1019 set value @ vue.runtime.esm.js:1064 finalizeNavigation @ vue-router.mjs?v=093df986:3503 (匿名) @ vue-router.mjs?v=093df986:3577 Promise.then (匿名) @ vue-router.mjs?v=093df986:3574 (匿名) @ vue-router.mjs?v=093df986:599 popStateHandler @ vue-router.mjs?v=093df986:598了解此错误AI list.vue:392 Uncaught (in promise) undefined
08-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值