
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
FrontEnd SPA Enterprise Framework
Setaria框架主要用于解决进行应用开发时经常面对的公共场景。
用于在本地进行前端的开发与调试。
1.使用国内镜像
npm config set registry https://registry.npm.taobao.org
// 配置后可通过下面方式来验证是否成功
npm config get registry
用于安装项目所需的第三方依赖包
版本管理工具。用于下载项目的代码和在开发时进行代码和文档的版本管理。
# 下载工程到本地
git clone https://github.com/bluejfox/setaria.git
# 进入工程目录
cd setaria
# 安装项目依赖
yarn install
支持各种主流浏览器(Chrome, Firefox, Safari)和Internet Explorer 9+.
约定一个地方生产和消费初始化数据
// 在app.js中将传入new Vue构造函数中的组件配置信息放置到 `Setaria.config.entry` 中
new Setaria({
// Vue入口组件配置信息
entry: {
// 原new Vue构造函数参数
el: '#app',
// 原new Vue构造函数参数
render: h => h(App)
},
// 定义getInitialState函数,必须返回Promise对象
getInitialState ({ http }) {
return new Promise((resolve, reject) => {
http.biz.get('user', { showLoading: true })
.then((res) => {
const { data } = res.data
// 返回值会由Setaria存入Vuex中,请根据实际情况构建适合的initialState结构
resolve({ user: data })
})
.catch((error) => {
reject(error)
})
})
},
loading: LoadingComponent,
error: ErrorComponent,
http: {
defaults: {},
biz: {
}
},
routes
})
getInitialState函数会在整个应用最开始执行,返回值会作为全局共享的数据。执行成功后框架会初始化根Vue实例,之后在Vue实例中可以通过 this.$store.getters[constants.STORE_KEY.GET_INITIAL_STATE] 直接获取到这份数据。
computed: {
initialState() {
const { data, error } = this.$store.getters[constants.STORE_KEY.GET_INITIAL_STATE];
return data;
}
},
运行时配置中,getInitialState 的返回值
当运行时配置中,getInitialState throw Error 时,会将错误储存在 error 中。
重新执行 getInitialState 方法,并获取新数据。
import Setaria from 'setaria'
Setaria.refreshInitialState()
// 或者在Vue实例内使用如下方式执行
// this.$setaria.api.refreshInitialState()
通过Vuex使用constants.STORE_KEY.SET_INITIAL_STATE mutation将数据手动保存至全局Vuex Module中
import { constants } from 'setaria';
this.$store.commit(constants.STORE_KEY.SET_INITIAL_STATE, {
data: {
user: {
id: 'setaria-user',
sex: 'gender'
}
}
})
前端页面中,基于vue的前端应用一般情况下需要捕获三个错误处理接口:
注: Vue从2.6.0版本之后,在vue实例内的 生命周期函数(created等) 和 事件钩子函数(v-on DOM 监听器内部) 抛出的普通 error 和 promise error 都可以捕获并统一从 errorHandler 接口抛出。
因此,Setaria提供了一套统一的错误处理方案,将如上接口进行封装并触发
config.errorHandler配置的函数,并把不同类型的错误信息(字符串,promise等)通过ApplicationError(执行期异常)和ServiceError(服务调用异常)传递,方便对错误进行后续的操作(页面提示等)
new Setaria({
/**
* @param {ApplicationError} error 封装的错误对象
* @param {string} type
* 'NORMAL_ERROR': 0, 非Vue组件的常规错误
* 'PROMISE_UNREJECT_ERROR': 1, Promise回调函数中的错误
* 'VUE_ERROR': 2 从 Vue 2.2.0 起,Vue组件生命周期钩子里的错误可以被捕获。从 Vue 2.4.0 起,Vue组件自定义事件句柄内部的错误可以被捕获。
* @param {object} origin 原始错误对象
**/
errorHandler(error, type, origin) => {
const exception = {
// 错误code
code: error.errorCode,
// 错误消息
message: error.errorMessage,
// 后端request唯一ID
requestId: error.requestId,
// 后端业务单据号
oddNumber: error.oddNumber,
// 错误显示方式 0 silent; 1 message.warn; 2 message.error; 4 notification; 9 page
showType: error.showType
}
alert(exception.message)
},
http: {
}
})
抛出普通异常信息,一般用于在处理中抛出指定业务异常
import { ApplicationError } from 'setaria'
// MCM006E为在Setaria.config.message中定义的消息ID
throw new ApplicationError('MCM006E')
抛出服务异常信息,当服务端返回异常时,异常信息会用此类型包装后抛出
错误码
错误消息
后端请求唯一标识ID,一般用于辅助快速查找后端错误
错误渲染方式(0 静默; 1 message.warn; 2 message.error; 4 notification; 9 page)
MIT
FAQs
Enterprise Frontend Framework base on Vue
The npm package setaria receives a total of 0 weekly downloads. As such, setaria popularity was classified as not popular.
We found that setaria demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.