当使用vue3+vite使用语法糖setup时,要注意写法.

第一种写法就是<script> 标签里面配置 setup,另一种是:export default 类里配置 setup() 方法,

我们只需要使用一种方法即可,混用了就会报错了。

解决: 第一种

<script setup>

import {ref} from 'vue'

import { Toast } from 'vant';

import Index from '../pages/Index.vue'

import Team from '../pages/Team.vue'

const onClickLeft = () => alert(1);

const onClickRight = () => alert(2);

const active = ref('index');

const onChange = (index) => Toast(`标签 ${index}`);

</script>

第二种:

<script>

import {ref} from 'vue'

import { Toast } from 'vant';

import Index from '../pages/Index.vue'

import Team from '../pages/Team.vue'

export default {

name: 'BasicLayout',

setup() {

const onClickLeft = () => alert(1);

const onClickRight = () => alert(2);

const active = ref('index');

const onChange = (index) => Toast(`标签 ${index}`);

return {

onClickLeft,

onClickRight,

onChange,

active

};

}

};

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐