-
Notifications
You must be signed in to change notification settings - Fork 5
vue.js #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
router/index.jsimport Vue from 'vue';
import Router from 'vue-router';
import HelloWorld from '@/components/HelloWorld';
import Login from '@/components/Login';
import SignUp from '@/components/SignUp';
Vue.use(Router);
let router = new Router({
// 数组中的每一个配置项为一个route record
routes: [
// 所有找不到的路径
{
path: '*',
redirect: '/login'
},
// 首页
{
path: '/',
redirect: '/login'
},
// 受保护的页面
{
path: '/hello',
name: 'HelloWorld',
component: HelloWorld,
meta: {
requiresAuth: true
}
},
{
path: '/login',
name: 'Login',
component: Login
},
{
path: '/sign-up',
name: 'SignUp',
component: SignUp
}
]
});
// Navigation Guards
router.beforeEach((to, from, next) => {
let currentUser = firebase.auth().currentUser;
// route record可以嵌套, 所以route.matched返回的是一个数组
let requiresAuth = to.matched.some(record => record.meta.requiresAuth);
if (requiresAuth && !currentUser) {
next('login');
} else if (!requiresAuth && currentUser) {
next('hello');
} else {
next();
}
});
export default router; |
问题
设置背景图的最佳实践
按钮背景图: fontawesome和美工给的两种版本, 如下使用: <el-button size="mini" title="Import" type="success" @click="handleImport()">
<img :src="require('@/assets/import.png')" alt="import">
</el-button>
<el-button size="mini" title="Save all" type="success" @click="saveAllFields">
<img :src="`${require('@/assets/xxx.png')}`" alt="import">
</el-button>
<el-button size="mini" title="Undo" type="success" @click="undo()" >
<icon name="undo"/>
</el-button> 动态引入图片此处product.image_url实际值比如为: 来源: |
dndhttps://hejx.herokuapp.com/vue-dndl/#!/ 富文本编辑器https://zhuanlan.zhihu.com/p/43416702 集成lodash最简单的方案: import _ from 'lodash';
Vue.set(Vue.prototype, '_', _); 另lodash中的 详见: https://stackoverflow.com/questions/37694243/using-lodash-in-all-of-vue-component-template |
动态设定axios的baseURL使用webpack的DefinePlugin watch $props change all at once来自: How to watch prop change in Vue.js component? <template>
<div>
{{count}}</div>
</template>
<script>
export default {
name: 'test',
props: ['count'],
watch: {
'$props':{
handler: function (val, oldVal) {
console.log('watch', val)
},
deep: true
}
},
mounted() {
console.log(this.count)
}
}
</script> |
Uh oh!
There was an error while loading. Please reload this page.
vue-cli建的项目如何升级vue的版本.
在项目目录里运行
npm upgrade vue vue-template-compiler
,不出意外的话,可以正常运行和 build。如果有任何问题,删除 node_modules 文件夹然后重新运行npm i
即可。.sync modifer
https://alligator.io/vuejs/upgrading-vue-2.3/
.sync
相当于input版本的v-model
, 适用于非input组件.:prop.sync=”binding”
会被展开为:prop=”binding” @update:prop=”value => binding = value”
但你依然无法在child组件中直接修改parent传过来的属性, 但可以通过`$emit('update:prop', 'some value')的方式去修改父组件传过来的prop.
例子
再来一例
嵌套的.sync
最外层(App.vue)
子(MyDialog.vue):
在MyDialog的
el-dialog
上不能使用:visibile.sync
这是因为在点el-dialog的关闭按钮时, 如果加了.sync那么el-dialog会兼听 update:visible事件, 尝试修改my-dialog中的props: ['visible'], 而props是不能直接修改的, 这时可以去掉.sync
然后在close回调中手动向最外层emit一个update事件, 如下(加一个@close
)或者, 将
:show-close
设置为false
. 用户只能通过点击cancel按钮来关闭窗口.xxxx
https://medium.com/@anas.mammeri/vue-2-firebase-how-to-build-a-vue-app-with-firebase-authentication-system-in-15-minutes-fdce6f289c3c
How to build your first Vue.js component
Vue’s new and improved prop.sync
References
https://juejin.im/post/59097cd7a22b9d0065fb61d2
The text was updated successfully, but these errors were encountered: