这段代码无法运行的原因可能有以下几点:

  1. 缺少引入 Vue.js 的代码,需要在<head>标签中添加以下代码:

    <script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>

  2. 在 Vue 实例中的 methods 中的函数需要用 ES6 箭头函数来定义,修改为以下代码:

    changeTab: (tab) => { if (tab === 'hit') { this.currentView = 'hit'; this.isHitmovie = true; this.isClassicmovie = false; } else if (tab === 'classic') { this.currentView = 'classic'; this.isHitmovie = false; this.isClassicmovie = true; } }

  3. 在组件的 template 中,需要使用 ES6 模板字符串,即在反引号``中编写 HTML 代码,修改为以下代码:

    template: <div class='main'>

    <span>{{ index + 1 }}</span> {{ movie.name }} <span>{{ movie.star }}</span> <button @click='removeMovie(index)'>删除

` `

修改以上代码后,应该可以正常运行该页面。

Vue.js 选项卡切换效果代码无法运行?常见问题及解决方案

原文地址: https://www.cveoy.top/t/topic/mkZL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录