Skip to content

Utils

使用 utils/目录在整个应用程序中自动导入你的工具函数

它只支持第一层扫描 不支持第二层

使用方法

新建工具类

新建 utils/tools.js 文件,里面写

js
const add = (x, y) => {
  return x + y;
};

const del = (x, y) => {
  return x - y;
};

export default {
  add,
  del,
};

页面使用

html
<script setup>
  const composables_data_1 = tools.add(1, 2);
  const composables_data_2 = tools.del(12, 1);
</script>
<template>
  <div>
    首页
    <el-button type="primary" @click="gotourl('login')">跳转到登录页</el-button>
    <el-button type="primary" @click="gotourl('about')"
      >跳转到about页面</el-button
    >
    <el-button type="primary" @click="gotourl('admin')"
      >跳转到admin页面</el-button
    >
    <el-button type="primary" @click="gotourl('user')"
      >跳转到user页面</el-button
    >
    {{ composables_data_1 }} {{ composables_data_2 }}
  </div>
</template>