Exercises for chapter 2
Enhancing MathPlugin
Enhance our MathPlugin
with trigonometrical functions (sine, cosine, and tangent).
Actually, it is just about adding the missing directives and using the Math
object's functions in it. Open VueMathPlugin.js
and add the following:
//VueMathPlugin.js
export default {
install: function (Vue) {
Vue.directive('square', function (el, binding) {
el.innerHTML = Math.pow(binding.value, 2);
});
Vue.directive('sqrt', function (el, binding) {
el.innerHTML = Math.sqrt(binding.value);
});
Vue.directive('sin', function (el, binding) { el.innerHTML = Math.sin(binding.value); }); Vue.directive('cos', function (el, binding) { el.innerHTML = Math.cos(binding.value); ...
Get Learning Vue.js 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.